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

Re: trailing spaces

Thread Previous | Thread Next
From:
Roger Horne
Date:
August 21, 2003 01:00
Subject:
Re: trailing spaces
Message ID:
Marcel-1.53-0821075526-c72Wr#W@hrothgar.hereot
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:roger@number7.demon.co.uk


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About