Perl Cannot change constant element in substitution

I have Perl Script to remove unnecessary tags that bloat the xml pdf files that I create

#!/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;

      

This Script results in the following error.

Unable to change persistent element in lookup (s ///) in d: \ Temp \ PDFPatch2.pl line 1 7, next to "s / [\ t] * <\? TemplateDesigner StyleID aped2 \?> \ N // gi; " Execution d: \ Temp \ PDFPatch2.pl canceled due to compilation errors.

Sorry, I don't know much about perl.

+3


source to share


1 answer


Do not turn off strict

. Turn on warnings

.



It may be clear to you that you typed line 17 and missed it $

before $line

.

+13


source







All Articles