Re: trailing spaces

[email protected] (Roger Horne) Thu, 21 Aug 2003 08:55:26 +0100 (BST)
Newsgroups perl.riscos
Message-ID <Marcel-1.53-0821075526-c72Wr#[email protected]>
On Wed 20 Aug, James Taylor wrote:
 
> But, more usefully, the fishing rod is:
> 
>     Learning Perl, 3rd edition
>     http://www.oreilly.com/catalog/lperl3/

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
-- 
Roger Horne, 11 New Square, Lincoln's Inn, London WC2A 3QB
mailto:[email protected]