in reply to Archive mail into a database
It seems to me that you could get "unexpected" results by doing
That only sets the variable if the match is made; if no match is made, the variable retains its current value, which — because of the way you're using global variables — could be what was found in the previous file. I think I'd do it this way:$const{mail_to} = $1 if $mail =~ m/To: (.*?)\n/s;
That way, the variable gets — properly — undef if no match is made. Personally, I'd be inclined to pass the values as arguments to insert, rather than using global variables.($const{mail_to}) = $mail =~ m/To: (.*?)\n/s;
Update: need parens around the LHS when assigning to scalar from regex match
|
|---|