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

DWIM is Perl's answer to Gödel

In reply to Re: Tips for elegance by GrandFather
in thread Tips for elegance by hasimir44

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.