I have an installation script which behaviour differs undesired depending of prior execution of unrelated regex.
The script restarts services after completing the installation, but when
$supported =~ /\Q4.1.2/is not executed not all services are started.
I have absolutely no clue as to why not executing an otherwise unrelated regex changes the behaviour of regexs inside a function called later.
Is this behaviour caused by using an undefined variable in a regex?
It looks mighty strange and I have worked around the issue by not using an undefined variable in a regex
I have reduced the installation script to
use v5.30.0; my @stoppedGeneralServices = ( 'OP Mover', 'OP Monitor'); 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 =~ /\Q4.1.2/ if @ARGV; say "Start Basic Standard Services:"; startStandardServices( 'Config'); say "Start Remaining Standard Services:"; startStandardServices(); say "Start General Services:"; startGeneralServices(); 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; } } sub startGeneralServices { my $last = shift; my $name; while (@stoppedGeneralServices) { $name = pop @stoppedGeneralServices; say ' Starting $name=\'', $name, '\' $last=', defined $last ? + "'$last'" : 'undef', ' ($name=~/$last/i)=', ($name =~ /$last/i) ? 1 +: 0; last if $name =~ /$last/i; } }
When executed without arguments the output is:
D:\>surprise.pl 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: Starting $name='OP Data Server' $last=undef ($name=~/$last/i)=1 Start General Services: Starting $name='OP Monitor' $last=undef ($name=~/$last/i)=1 Installation completed
When executed with an argument the output is:
D:\>surprise.pl all 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: Starting $name='OP Data Server' $last=undef ($name=~/$last/i)=0 Starting $name='OP Calculation Server' $last=undef ($name=~/$last/i) +=0 Starting $name='OP OPC Client' $last=undef ($name=~/$last/i)=0 Start General Services: Starting $name='OP Monitor' $last=undef ($name=~/$last/i)=0 Starting $name='OP Mover' $last=undef ($name=~/$last/i)=0 Installation completed
In reply to Side effect of using undefined variable in regex by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |