> -----Original Message-----
> From: Hanson, Robert [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 02, 2002 2:21 PM
> To: 'Maciejewski, Thomas'
> Cc: [EMAIL PROTECTED]
> Subject: RE: C vs. Perl
> 
> 
> No flames from me.
> 
> One of Perl's strong/weak points is that there are too many ways to do
> something... I agree with that.  But it is up to the 
> programmer to implement
> solutions that make sense and are easy to maintain.  I personally like
> having the power to do what I need to do, which makes it my 
> responsibility
> to use that power wisely.
> 
> Some things that I avoid:
> 
> s/^\s*(.*?)\s*$/$1/,print for (<>);

I avoid that as well. From the perlfaq4:

 ...Although the simplest approach would seem to be:

    $string =~ s/^\s*(.*?)\s*$/$1/;

 This is unneccesarily slow, destructive, and fails with embedded newlines.
 It is much better faster to do this in two steps:

    $string =~ s/^\s+//;
    $string =~ s/\s+$//;

Also, I don't see the point of the list-context call to <>
(although the optimizer may be smart enough to avoid sucking
the file into memory; I'm not sure).

I would use this:

   s/^\s+//, s/\s+$//, print "$_\n" while <>;

> 
> Instead I use this:
> 
> foreach my $line ( <STDIN> ) {
>   $line =~ s/^\s*(.*?)\s*$/$1/; # trim space
>   print $line;
> }
> 

Not sure how much of an improvement that is. I find the Perl
statement modifiers to be a tremendous boon to readability.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to