Just for good marks and all.. when you are dealing with a regex expression that will match a whole line it is good form to use ^(matches the beginning of a line) and $(matches the end of a line) to speed processing. So your regex expression would change to:

/^\A(\S+) (\S+) (\S+) (\d+):$/;

Also, if you truly wanted $1 to be set you could do so by just executing the regex statement provided by MarkM.

So instead of:

my($wday, $mon, $mday, $time, $year) = $var =~ /\A(\S+) (\S+) (\S+) (\d+):/;
it would just be

$var =~ /\A(\S+) (\S+) (\S+) (\d+):/;
and $1 would be set equal to the first match

$2 to second

and so on

These are static/constant variables so to modify them you would have to assign them to a seperate variable as MarkM has done. If however you just need to display or store the results why generate additional variables?

If you are doing this over a large number of entries you also might want to look into optimizing your statements using the lookaheads (I think that is the correct term) which allow the regex expression to set a qualifier before attempting to match any further into the string/line/block, etc..

example

(?:[SMTWF]) warning I know my syntax is off so please don't use this.
at the beginning of your regex string should help to quickly skip those lines which do not start with a capital letter from the days of the week, nifty huh?

Just my .02 cents since I love regex.

Dave -- Saving the world one node at a time


In reply to Re: Re: Regular Exp parsing by Zapawork
in thread Regular Exp parsing by Cupojava

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.