more useful options | |
PerlMonks |
Re: Weird Regex in CGI::Cookieby d_i_r_t_y (Monk) |
on Oct 16, 2003 at 00:59 UTC ( [id://299601]=note: print w/replies, xml ) | Need Help?? |
yes, it is broken. the reason is that the pattern is only matching the leading space and nothing else -- ie: which gives matched ' '; retained ''; str is 'blee blah ' to strip whitespace, the minimal match needs to be forcibly anchored to match to the end of the string, ie: s/^\s*(.+?)\s*$/$1/, which now successfully strips leading & training whitespace. however this is a poor way to do it. it is clearer and faster to use 2 regexps, one to strip leading \s, the other the trailing \s; ie:
using 2 regexps is also quite a bit faster than the single regexp too:
In Section
Seekers of Perl Wisdom
|
|