develooper Front page | perl.riscos | Postings from August 2003

Re: trailing spaces

Thread Previous | Thread Next
Roger Horne
August 21, 2003 01:00
Re: trailing spaces
Message ID:
On Wed 20 Aug, James Taylor wrote:
> But, more usefully, the fishing rod is:
>     Learning Perl, 3rd edition

That was the 1st (out of many) Perl book that I bought and I found it awful.
Horses for courses I suppose, but so far as I was concerned Programming Perl
was immeasurably better. 

The one I use most is, I think, the Perl Cookbook. It gives a recipe (1.14)
for trimming leading and trailing whitespace (which is basically what you
have suggested).

A point that I have never seen dealt with is why, in order to trim at both
ends, the recipe uses
  $string =~s/^\s+//; 
  $string =~s/\s+$//;
rather than say 
  $string =~s[^\s*(.*?)\s*$][$1];
(Typed without glasses on so I may have missed out a character or two ...)

Is the first version quicker (marginally)?

Roger Horne, 11 New Square, Lincoln's Inn, London WC2A 3QB

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About