In the updated example, the string '00000000000000000000' would not match the regex you specify for session (which expects hyphens), and therefore the contents of $session_id, $last_action_date, and $last_action_time would all be undefined. I usually do something like this (admittedly more verbose code):

my ($session_id, $last_action_date, $last_action_time) = (0,0,0); if ($session =~ /^(\d\d)-(\d{10})-(\d{8})$/) { $session_id = $1; $last_action_date = $2; $last_action_time = $3; } else { # print some kind of warning -- the session ID didn't match my regex +! }

I have generally found that reliance on a regex match for code flow can be problematical ... external data is not always what I think it will be. You need to protect yourself from disaster a little more effectively.

Update: I see that you updated your session example ... even so, the rest of the post has some merit, I think. I would probably use split /-/ for that particular case, anyway, and test that the split produced the requisite number of tokens before I rushed off to use the data.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

In reply to Re: Large Variable to small variables, why dont they display by ptum
in thread Large Variable to small variables, why dont they display by barrycarlyon

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.