Thomas Bätzler wrote:
Dermot Paikkos <[EMAIL PROTECTED]> coded:
[...]
#!/bin/perl
my $root = "/home/";
my $file = "home.txt";
open(FH,$file) or die "Can't open $file: $!\n";
while (<FH>) {
chomp;
s/\s*$//; # delete all whitespace at the end of the string
You should use \s+ instead of \s* as it is more efficient:
$ perl -e'
use Benchmark qw/cmpthese/;
@a = ( "a".."z", "A".."Z", 0..9 );
@b = map {
join "", map( $a[ rand @a ], 0 .. 10 + rand 10 ), " " x rand 10
} 1 .. 1000;
cmpthese( -20, {
star => sub { my @x = @b; s/\s*$// for @x; return @x },
plus => sub { my @x = @b; s/\s+$// for @x; return @x }
} );
'
Rate star plus
star 131/s -- -66%
plus 390/s 198% --
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>