On Dec 12, 2003, at 1:51 PM, Dan Anderson wrote:

Is there a way to chomp all whitespace both at the beginning and end of
a string?  I was thinking of using a regexp like s[^\s*?][]sg and
s[\s*?$][]sg;  Is there a better way?  (I'm thinking of PHP's trim
function)

I imagine so because I don't think your expressions trim anything. You made them non-greedy and gave them the option to match 0 spaces. Since that's pretty ungreedy, I'm betting they'll do just that. Also, there's no need form either modifer /s or /g.


sub trim { $_[0] =~ s/^\s*//; $_[0] =~ s/\s*$//; $_[0]; }

James

P.S. If it makes you feel any better, I don't think this is covered in Network Programming with Perl. ;)


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to