I don't think the code does what you think it's doing:

my ($session_id, $last_action_date, $last_action_time) = $session =- / ^(\d\d)-(\d(10))-(\d(8))$/;

If you copy'n'pasted the code, then the operators in bold tags, =-, won't do a regular expression match, and depending on what's stored in $_, you should get an Use of uninitialized value ... warning.

If you transferred the code by hand and made a typo just when typing it in, I think we'll need to get a more accurate error description of what goes wrong and how. I find it curious that your session IDs can only have two digits, and your action times have eight digits (HHMMSS), while your dates have 10 digits (YYYYMMDD) - something is very fishy in your format description.

Please take the time to post some relevant-yet-anonymized data and what you're actually trying to do with it. As your question title mentions splitting, maybe split is what you actually want to do:

my ($session_id, $last_action_date, $last_action_time) = split /-/, $s +ession;

Update: liverpole has even better eyes than I have - you need curly brackets for counting repetitions - what you're typing your code in from, it has a very bad font or you really need glasses.

Update2: Neither - nor : are what Perl considers a digit when matching against \d. The only chars allowable as digits are the following ten chars:

0 1 2 3 4 5 6 7 8 9

I would still use split to get at the separate fields, or use unpack or a more specific regular expression:

# split: my @fields = split /-/, $session; die "Weird timestamp in >>$session<<" unless @fields == 5; my ($session_id) = $fields[0]; my ($last_action_date) = join "-", @fields[1,2,3]; my ($last_action_time) = $fields[4]; # unpack: my ($session_id,$last_action_date,$last_action_time) = unpack "A2xA10x +A8", $session; # regex: $session =~ /^(\d{2})-(\d{4}-\d{2}-\d{2})-(\d\d:\d\d:\d\d)$/ or die "Weird timestamp in >>$session<<" my ($session_id,$last_action_date,$last_action_time) = ($1,$2,$3);

In reply to Re: A Question on assigning variables from a big variable by Corion
in thread A Question on assigning variables from a big variable 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.