#!/usr/bin/perl -w use strict; # create sample task list my $tasks = [ [ "A", "1.1"], [ "B", "1.2"], [ "C", "2.4"], [ "D", "2.9"], [ "E", "1.3.1"], ]; my $task_name = "C"; # use to hold task name i'm searching for my $task_version = ""; # use to hold task version i'm searching for my ($cache_name, $cache_version); # use to hold data from task list my ($match_name, $match_version); # use to hold result of regex match foreach my $array ( @$tasks ) { $cache_name = $array->[0]; # get task name $cache_version = $array->[1]; # get task version # error occurs here $match_name = ($cache_name =~ /^$task_name$/i) ? "match" : "no match"; $match_version = ($cache_version =~ /$task_version/i) ? "match" : "no match"; info( 0, 24, "[$cache_name] =~ /^$task_name\$/i", $match_name ); info( 4, 24, "[$cache_version] =~ /$task_version/i", $match_version ); } ## Info Subroutine ## sub info { my $indent = shift; my $width = shift() - $indent; my $msg = shift; my $result = shift; my $margin = " " x $indent; printf( "%s%-${width}s | %10s\n", $margin, $msg ? substr( $msg, 0, 60 ) : "", $result ? substr( $result, 0, 10 ) : "" ); } ######## OUTPUT ######## [A] =~ /^C$/i | no match [1.1] =~ //i | match [B] =~ /^C$/i | no match [1.2] =~ //i | match [C] =~ /^C$/i | match [2.4] =~ //i | no match <-- unexpected [D] =~ /^C$/i | no match [2.9] =~ //i | no match <-- unexpected [E] =~ /^C$/i | no match [1.3.1] =~ //i | no match <-- unexpected #### #!/usr/bin/perl -w use strict; # create sample task list my $tasks = [ [ "A", "1.1"], [ "B", "1.2"], [ "C", "2.4"], [ "D", "2.9"], [ "E", "1.3.1"], ]; my $task_name = "C"; # use to hold task name i'm searching for my $task_version = ""; # use to hold task version i'm searching for my ($cache_name, $cache_version); # use to hold data from task list my ($match_name, $match_version); # use to hold result of regex match foreach my $array ( @$tasks ) { $cache_name = $array->[0]; # get task name $cache_version = $array->[1]; # get task version # reversing order of regex works around this bug $match_version = ($cache_version =~ /$task_version/i) ? "match" : "no match"; $match_name = ($cache_name =~ /^$task_name$/i) ? "match" : "no match"; info( 0, 24, "[$cache_name] =~ /^$task_name\$/i", $match_name ); info( 4, 24, "[$cache_version] =~ /$task_version/i", $match_version ); } ## Info Subroutine ## sub info { my $indent = shift; my $width = shift() - $indent; my $msg = shift; my $result = shift; my $margin = " " x $indent; printf( "%s%-${width}s | %10s\n", $margin, $msg ? substr( $msg, 0, 60 ) : "", $result ? substr( $result, 0, 10 ) : "" ); } ######## OUTPUT ######## [A] =~ /^C$/i | no match [1.1] =~ //i | match [B] =~ /^C$/i | no match [1.2] =~ //i | match [C] =~ /^C$/i | match [2.4] =~ //i | match <-- EXPECTED [D] =~ /^C$/i | no match [2.9] =~ //i | no match <-- unexpected [E] =~ /^C$/i | no match [1.3.1] =~ //i | no match <-- unexpected