in reply to need help on declaring variables
When using regular expressions it is usually a good idea to put them in a condition.
The greater danger of your code, apart from using uninitialized $1 and $2, is using an initialized $1 and $2 from a previous match. The capture buffer variables $1 etc are not reset to undef when a match fails so you may produce erroneous output without any outward sign.if ( my ( $raw_dt, $refs ) = /^(.*) UTC.*refs = (\d+)$/ ) { my $dt = $Strp->parse_datetime($raw_dt); ... } else { # possible error condition }
|
|---|