which didn't work either. I'm already using use strict; use warnings;. I'm again pasting code that one can run:if ($str =~ /^$var/)
I hope this helps... Thanks.use strict; use warnings; my %hashArray; my $str; my @bigArray; # Adding to an array in format <ip,server> push (@bigArray, "62.40.40.10,ServerOne"); push (@bigArray, "62.40.40.20,ServerTwo"); push (@bigArray, "62.40.40.30,ServerThree"); # Adding to hash $hashArray{"62.40.40.10"} = "ServerOne"; $hashArray{"62.40.40.20"} = "ServerTwo"; $hashArray{"62.40.40.30"} = "ServerThree"; my ($key, $value, $idx); foreach $str (@bigArray) { print $str . "\n"; # This prints all values correctly } while (($key, $value) = each (%hashArray)) { print "$key-$value\n"; } # above while statement too prints all correctly my $var = "62.40.40.30"; print "var: $var\n"; ## Please note that following part of code (foreach, if ## exists, while) doesn't work ## It doesn't give any error; simply says no match foreach $str (@bigArray) { print "$str\n"; if ($str =~ /^$var/) { print "IP address matched. Proceed to log trap!\n"; last; } else { print "Match not found.\n"; } } print "After for\n"; if (exists ($hashArray{$var})) { print $var . " exists in hash!\n"; } while (($key, $value) = each (%hashArray)) { print "KEY: $key\n"; if ($key eq $var) { print "IP Matches!\n"; } }
In reply to Re^2: Regular expression match in code
by truptivk
in thread Regular expression match in code
by truptivk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |