V
vali
A. Sinan Unur said:Thank you for the correction. I failed to notice the typo in vali's post.
Just followed up on Jurgen's one.
I was suprised to see just how much more efficient \s+ was compared to \s*.
That's what I thought when using it on my approach.
Finally, this supports my assertion that s/(^\s+|\s+$)//g; is not the same
as what the answer to the FAQ recommends.
That's right. I'll start using it (and check more often the FAQs).
Thanks (to all of you) for this (and other) insights !
__Vali
#! /usr/bin/perl
use strict;
use warnings;
use Benchmark ':all';
my $INPUT = [
'pear ',
' apple ',
'apple',
' orange ',
' mango ',
'mango',
' pear',
' cherry ',
'apple',
'',
];
sub s1 {
my @input = @{ $INPUT };
for (@input) {
s/^\s*//;
s/\s*$//;
}
}
sub faq {
my @input = @{ $INPUT };
for (@input) {
s/^\s+//;
s/\s+$//;
}
}
cmpthese 0, {
s1 => \&s1,
faq => \&faq,
};
__END__
D:\Home>perl t.pl
Rate s1 faq
s1 8638/s -- -25%
faq 11489/s 33% --
Sinan