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