efoss has asked for the wisdom of the Perl Monks concerning the following question:
This doesn't work. However, the following works, but only because all the files in "@array" have either 1 or 2 digits following the initial "KL". If there had been a file name in @array like "KL123_rest.txt" that I didn't want to push onto the array "@files", then my code wouldn't have worked.foreach $file (@array) { if ($file =~ /^KL\d{1|2}_/) { push (@files, $file); print "$file\n"; } }
How do I correctly quantify \d in this situation? Thanks. Ericforeach $file (@array) { if ($file =~ /^KL\d+_/) { push (@files, $file); print "$file\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: quantifiers with digits (\d{1|2} doesn't do what I expect)
by davido (Cardinal) on Aug 21, 2012 at 01:56 UTC | |
by efoss (Acolyte) on Aug 21, 2012 at 16:10 UTC | |
|
Re: quantifiers with digits (\d{1|2} doesn't do what I expect)
by BillKSmith (Monsignor) on Aug 21, 2012 at 02:55 UTC | |
|
Re: quantifiers with digits (\d{1|2} doesn't do what I expect)
by ricDeez (Scribe) on Aug 21, 2012 at 07:56 UTC |