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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |