Reputation: 324
I have Perl Script using to remove unnecessary tags that bloating xml pdf files i am creating
#!/usr/bin/perl
#use strict;
use DirHandle;
my $sourcefile = shift;
my $outputfile = "new" . $sourcefile;
open SOURCEFILE, "$sourcefile" or die;
open OUTPUTFILE, ">$outputfile" or die;
$flag = 0;
foreach $line (<SOURCEFILE>) {
if($line=~ /<\?templateDesigner StyleID aped2\?>\n/) {
if($flag == 1) {
line=~ s/[\t]*<\?templateDesigner StyleID aped2\?>\n//gi;
}
$flag=1;
}
elsif($line=~ /<\?templateDesigner StyleID aped3\?>\n/) {
if($flag == 1) {
$line=~ s/[\t]*<\?templateDesigner StyleID aped3\?>\n//gi;
}
$flag=1;
}
elsif($line=~ /<\?templateDesigner StyleID apcb1\?>\n/) {
if($flag == 1) {
$line=~ s/[\t]*<\?templateDesigner StyleID apcb1\?>\n//gi;
}
$flag=1;
}
else {
$flag=0;
}
print OUTPUTFILE $line;
}
close SOURCEFILE;
close OUTPUTFILE;
Result of me running this script is following error.
Can't modify constant item in substitution (s///) at d:\Temp\PDFPatch2.pl line 1 7, near "s/[\t]*<\?templateDesigner StyleID aped2\?>\n//gi;" Execution of d:\Temp\PDFPatch2.pl aborted due to compilation errors.
Sorry do not know much about perl.
Upvotes: 3
Views: 3761
Reputation: 53478
Don't turn off strict
.
Turn on warnings
.
This would perhaps make it clear that you've typoed on line 17, and omitted $
from in front of $line
.
Upvotes: 14