in reply to Regular Expression on special character and alphanumeric values
1) Assign directly to a variable without using $1. The list on the left can be expanded, especially useful when there is $2,$3, etc. I prefer to get a meaningful name ASAP.
my ($first) = string =~ /some regex with capture/;
2) Often the //= operator is useful:
Assigns $first to the null string if it is undefined. Introduced I think in Perl 5.10. You have something that evaluates to false, yet can be printed without an error.$first //= '';
|
|---|