Maybe I'm missing something really obvious, but if the - (dash) is optional, then mark it such in the regular expression...
my ($year, $num) = ($_ =~ /^(\d{4})-?(\d+)$/);
This way you will be guaranteed of getting both parts, regardless of whether a dash is present or not.
• another intruder with the mooring in the heart of the Perl
In reply to Re: simple regexp question
by grinder
in thread simple regexp question
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |