in reply to A better regex
You should always check for the success of a regex match before capturing the value in $1..$n
If the regex match fails you will end up having undefined value or some junk in $1. Always check for the success before you assign the captured values.
Your code should look like
if ( $zipfile =~ m/[AB]FILE_(\d+)/ ) { $day = $1; } else { # oops.. the file name is not what we expected .. # panic !! }
Hope this helps
-T
|
|---|