...which gives you the added bonus of scoping $tmp2. Plus, you don't have to check whether a character is present in your var before substituting it out.my $tmp2 = ""; $tmp2 = $2;
is better written as:if($tmp2 =~ m/\'/) { $tmp2 =~ s/\'/\\\'/g; # escape the single quotes.. }
If there's a single quote in $tmp2 it'll get escaped. Otherwise nothing happens. Note that you don't have to escape single-quotes within a regex.$tmp2 =~ s/'/\\'/g; # escape the single quotes..
Lastly if you're paranoid about non-Alphanumerics in your regex's check out the \Q modifier. This does what you want automatically within a regular expression without you having to do anything else.
Gary Blackburn
Trained Killer
Edited:Added my $tmp2=""; to really make $tmp2 defined. :-P
In reply to Re: Use of uninitialized value in pattern match (m//)
by Trimbach
in thread Use of uninitialized value in pattern match (m//)
by wolis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |