There area number of things I'd alter here. For a start using \d rather than the more cumbersome character class [0-9] helps as does using the quantifier {2} in the regex. Personally I prefer to reserve # for comments where possible so I'd choose something else for the regex delimiters.
Rather than using two arrays which you have to keep in sync, I'd use one array of hashes. That avoids having to use indexes everywhere to access the arrays.
Assigning the capture list directly to variables is often cleaner than using the special capture variables (my ($stamp, $name) = m<...>;), although in this case just using the capture variables directly is clean.
use strict; use warnings; my @ll = <DATA>; my @items; chomp @ll; foreach (@ll) { next if ! m<([A-Z][a-z]{2}\s\d{2}\s\d{2}:\d{2})\s(/.+\.Z)>; push @items, {stamp => $1, name => $2}; } print "$_->{name}: $_->{stamp}\n" for @items; __DATA__ Jun 05 20:08 /<path>/B1006-cnvexp.20060605.200841.Z Jun 05 20:09 /<path>/B1106-cnvexp.20060605.2008.Z Jun 05 20:09 /<path>/B11062-cnvexp.20060605.2008.Z
Prints:
/<path>/B1006-cnvexp.20060605.200841.Z: Jun 05 20:08 /<path>/B1106-cnvexp.20060605.2008.Z: Jun 05 20:09 /<path>/B11062-cnvexp.20060605.2008.Z: Jun 05 20:09
In reply to Re: Tips for elegance
by GrandFather
in thread Tips for elegance
by hasimir44
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |