in reply to Re^3: Side effect of using undefined variable in regex
in thread Side effect of using undefined variable in regex

I've edited my post because putting the (?{ }) block after trying to match 4.1.2 was the obvious reason why it didn't called again. But I've tried this:

use v5.20.0; my @stoppedStandardServices = ( 'OP OPC Client', 'OP Calculation Serve +r', 'OP Data Server', 'OP Configuration Server', 'OP Log Server', 'OP + Time Server', 'ONC RPC PortMapper'); my $supported = '4.0.0,4.0.1,4.1.0,4.1.1,4.1.2'; $supported =~ /.(?{say '>>> In the regex'})/ if @ARGV; "4.1.2" =~ //; say "Start Basic Standard Services:"; startStandardServices( 'Config'); say "Start Remaining Standard Services:"; startStandardServices(); say "Installation completed"; sub startStandardServices { my $last = shift; my $name; while (@stoppedStandardServices) { $name = pop @stoppedStandardServices; say ' Starting $name=\'', $name, '\' $last=', defined $last ? + "'$last'" : 'undef', ' ($name=~/$last/i)=', ($name =~ /$last/i) ? 1 +: 0; last if $name =~ /$last/i; } }
And with one parameter I get the output:
>>> In the regex >>> In the regex Start Basic Standard Services: Starting $name='ONC RPC PortMapper' $last='Config' ($name=~/$last/i) +=0 Starting $name='OP Time Server' $last='Config' ($name=~/$last/i)=0 Starting $name='OP Log Server' $last='Config' ($name=~/$last/i)=0 Starting $name='OP Configuration Server' $last='Config' ($name=~/$la +st/i)=1 Start Remaining Standard Services: 'Config' Starting $name='OP Data Server' $last=undef ($name=~/$last/i)=1 'Config' Installation completed
Why doesn't ">>> In the regex" appear again when $last is undef, and how is the string 'Config' printed?

Replies are listed 'Best First'.
Re^5: Side effect of using undefined variable in regex
by haukex (Archbishop) on Jul 01, 2019 at 14:59 UTC
    Why doesn't ">>> In the regex" appear again when $last is undef, and how is the string 'Config' printed?

    Sorry, I can't reproduce that on any of my Perl builds, 5.20.0 through 5.30.0 (Linux). The output I get in all cases is:

    >>> In the regex >>> In the regex Start Basic Standard Services: Starting $name='ONC RPC PortMapper' $last='Config' ($name=~/$last/i) +=0 Starting $name='OP Time Server' $last='Config' ($name=~/$last/i)=0 Starting $name='OP Log Server' $last='Config' ($name=~/$last/i)=0 Starting $name='OP Configuration Server' $last='Config' ($name=~/$la +st/i)=1 Start Remaining Standard Services: >>> In the regex Starting $name='OP Data Server' $last=undef ($name=~/$last/i)=1 >>> In the regex Installation completed

      I don't get it on Linux either. Only on my 5.26 strawberry perl...

        Ok, can confirm, that's definitely a bug :-) Reported as #134246!