Perl does not reevaluate regex variable -


i in charge of upgrading perl script perl v5.6.1 (2001) v5.20.2 (2015). have these 2 regex variable:

foreach (@filelist) {     chomp;     $file = $_;     if ( $file =~ qr/.+/o ) {         if ( $baseline ) {              $baselineregexpa = qr/^\q$baseline\e\\/io; #these 2 regexes             $baselineregexpb = qr/^\q$baseline\e;/io;  #these 2 regexes              if ( $file =~ /$baselineregexpa/ ) {                 #...              } elsif ( (!($file =~ /$baselineregexpb/)) && (!(lc( $file ) eq lc( $baseline ) )) ) {                 $baseline = $file;             }         }      } } 

so, have 2 questions:

  1. in old perl version, $baselineregexpa , $baselineregexpb gets reevaluate every time $baseline changes, in new perl, not. how make changes? i've tried $baselineregexpa, still not change.

  2. in old perl, $baselineregexpa evals to: (?i-xsm:^f:\\dd\\), , in new perl, evals (?^i:^f:\\dd\\). questions is, there different between ?i-xsm:^ , ?^i:^?

thanks much, unfortunately, these legacy scripts , don't know perl.

  1. the o modifier prevents re-evaluating variables substituted regexes. it's curious didn't happen on 5.6, it's because qr still new in version. removing (changing /io /i) should make things work way expect.

  2. the (?i-xsm) encodes regex modifier flags in effect (i turned on, x, s, , m turned off). sometime around perl 5.14, perl got new regex modifier flags, change stringification of regexes. since backwards-incompatible change, decided in way limit hassle caused adding new flags down road, , ^ character used represent "default" set of flags. (?^i) means "the default flags, plus i flag". both mean same thing, , there's nothing should worry about.


Comments