From the
docs for perlre
NOTE: Failed matches in Perl do not reset the match variables . . .
You can see this more clearly with a slightly modified version of your code where the leading characters are 'xxx' instead of 'zzz'.
my @files=("zzz.21.yy.ccc", "xxx.220.ccc" );
foreach my $name (@files)
{
my $match="no ";
$match="yes" if ( $name =~ /(^[a-z]{3})\.(\d{2,3})\..*\.ccc/) ;
print "$match, $name, match1: $1, match2: $2\n";
}
The variables $1 and $2 retain the values they had on the previous successful match.
yes, zzz.21.yy.ccc, match1: zzz, match2: 21
no , xxx.220.ccc, match1: zzz, match2: 21
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.