in reply to curious regex result for perl 5.8.8
If there is no match the content of the capture variables is bogus. The fact that their content is a different value of bogus between different versions of Perl is not so important as the fact that the value is not defined when there is no match. Your code would be better written:
use strict; use warnings; my @files = ("zzz.21.yy.ccc", "zzz.220.ccc"); foreach my $name (@files) { chomp $name; if ($name =~ /(^[a-z]{3})\.(\d{2,3})\..*\.ccc/) { print "yes, $name, match1: $1, match2: $2\n"; } else { print "no, $name\n"; } }
Prints:
yes, zzz.21.yy.ccc, match1: zzz, match2: 21 no, zzz.220.ccc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: curious regex result for perl 5.8.8
by dave_the_m (Monsignor) on Jun 21, 2016 at 10:01 UTC | |
by GrandFather (Saint) on Jun 22, 2016 at 02:02 UTC | |
by Anonymous Monk on Jun 22, 2016 at 02:15 UTC | |
by GrandFather (Saint) on Jun 22, 2016 at 04:13 UTC |