kp2a has asked for the wisdom of the Perl Monks concerning the following question:

unexpected "Substitution pattern not terminated" nothing in my code looks like regexp or s/// Error message
[john@primary duplicates] 21:13 $ perl -c fixip.pl Use of /c modifier is meaningless in s/// at fixip.pl line 21. Substitution pattern not terminated at fixip.pl line 19.
15 $I->execute; 16 17 while(my $i = $I->fetchrow_hashref) { 18 19 my $cnip = ($$i{s.misc04} << 16) + $$i{s.misc05}; 20 21 my $onip = ($$i{o.misc04} << 16) + $$i{o.misc05}; 22 23 $BILLMAX->do("UPDATE reset SET currentnip = $cnip,oldnip = $onip WHERE service = $$i{r.service}"); 24 }

Replies are listed 'Best First'.
Re: Substitution pattern not terminated
by AnomalousMonk (Archbishop) on Nov 09, 2016 at 02:08 UTC

    Further to tybalt89's reply: The  s/// substitution operator can take arbitrary delmiters (within reason), so expressions like  s.misc04 in your code are confusing Perl. Don't do that.

    c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 'abXcd'; print qq{'$x'}; ;; $x =~ s.X.Y.; print qq{'$x'}; " 'abXcd' 'abYcd'
    Please see discussion of  s/PATTERN/REPLACEMENT/ in Regexp Quote-Like Operators in perlop.

    Update: If you do not have strictures enabled (see use strict;), expressions like  o.misc04 or  r.service will be meaningless to Perl (unless you happen to have functions named o() or service(), etc., defined). With strictures enabled, the expression won't compile. Enabling warnings (use warnings;) can be very helpful as well.

    c:\@Work\Perl\monks>perl -le "my $hr = { 'o.misc04' => 'xxx' }; print qq/'$$hr{o.misc04}'/; " '' c:\@Work\Perl\monks>perl -le "use warnings; ;; my $hr = { 'o.misc04' => 'xxx' }; print qq/'$$hr{o.misc04}'/; " Unquoted string "o" may clash with future reserved word at -e line 1. Use of uninitialized value in concatenation (.) or string at -e line 1 +. '' c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $hr = { 'o.misc04' => 'xxx' }; print qq/'$$hr{o.misc04}'/; " Bareword "o" not allowed while "strict subs" in use at -e line 1. Bareword "misc04" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors.

    Further Update: And I should have included one further code variation:

    c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $hr = { 'o.misc04' => 'xxx' }; print qq/'$$hr{ 'o.misc04' }'/; " 'xxx'


    Give a man a fish:  <%-{-{-{-<

Re: Substitution pattern not terminated
by tybalt89 (Monsignor) on Nov 09, 2016 at 01:48 UTC

    s.pattern.replacement. is valid s///

Re: Substitution pattern not terminated
by Marshall (Canon) on Nov 09, 2016 at 02:51 UTC
    I was not able to replicate this issue with warnings and strict enabled. With both of those enabled, other errors appear before even getting to this "Substitution" problem with "s.". E.g. "bareword "o.misc04" is not allowed". Note that $$i{s.misc04} is not a valid hash key under "warnings" and "strict".

    Essentially you have a problem in the code that even allowed you got get to an obscure error message. Fix the thing that caused that initial problem (use both strict; and warnings;).

    Also, I personally highly recommend the arrow notation when de-referencing say a hash ref in this case.

    #!/usr/bin/perl use strict; use warnings; my %h = ("o.misc04" => 1, "o.misc05" => 10); my $i = \%h; my $onip = ($$i{"o.misc04"} << 4) + $$i{"o.misc05"}; print "\$onip is: $onip\n"; $onip = ($i->{"o.misc04"} << 4) + $i->{"o.misc05"}; print "\$onip is: $onip\n"; __END__ prints: $onip is: 26 # 1<<4 +10 = 16 + 10 = 26 $onip is: 26 # 1<<4 +10 = 16 + 10 = 26