in reply to Problem with input strings that have "[]" brackets
Please also note that when looking for a pattern contained as a substring of a line, it can be much simpler and clearer to use the index function:
say
substr+lc crypt(qw $i3 SI$),4,5
The index function gives a negative one if the match wasn't found, and the position of the match if it was (which can be a zero if the match was at the beginning), hence the comparison of zero or greater:my $line = ' [Category("notestrecord")]'; my $pattern = 'Category("notestrecord")'; if (index($line, $pattern) >= 0) { print "We have a match!\n"; } else { print "No match!\n"; }
if (index($line, $pattern) >= 0) { ... }
|
---|
In Section
Seekers of Perl Wisdom