Hello again Steve
Am Dienstag, 8. M�rz 2005 15.46 schrieb John Doe:
> Hello Steven
[...]
> > s/// operates by default on $_, as many other built-in functions do,
> > thus:
> >
> > @parts = map { do { s/\s*$//; $_ } @parts;
>
> Thanks :-)
> [just a very little typo note: one right '}' is missing]
>
> What do you think if one would also put an o modifier here?
>
> @parts = map { do { s/\s*$//o; $_ } } @parts;
>
> Would this still be (much) slower than the tr/// version?
> [hmm... ok... I could test it myself]
>
> > Also, consider using the tr operator instead of s/// for speed-up
> > purposes.
>
> Oups - I missed this possibility... which would be (just to be complete :-)
>
> @parts = map { do { tr/ //d; $_ }} @parts; # d modifier required
[...]
I just realized that the tr is not applicable in the case of the present data
because column 4 which contains spaces _within_ the value
(e.g. "VAL B").
Then I ran the following test with (for me) not very expected results - maybe
the test is bad designed?
# I ran 3 times:
use strict;
use warnings;
use Benchmark 'cmpthese';
my $line='ATOM 2909 CG1 VAL B'; # incomplete demo line!
my @parts= $line=~/^(.{7}).{6}(.{6}).{5}/o;
cmpthese( -1, {
common => 'my @[EMAIL PROTECTED];',
s => 'my @[EMAIL PROTECTED]; @p=map {do{s/\s*$//; $_}} @p;',
so => 'my @[EMAIL PROTECTED]; @p=map {do{s/\s*$//o; $_}} @p;',
tr => 'my @[EMAIL PROTECTED]; @p=map {do{tr/ //d; $_}} @p;'
} ) ;
# With the results:
Rate tr s so common
tr 607350/s -- -1% -2% -47%
s 613304/s 1% -- -1% -46%
so 619376/s 2% 1% -- -46%
common 1137401/s 87% 85% 84% --
Rate s tr so common
s 607350/s -- -0% -1% -45%
tr 607350/s 0% -- -1% -45%
so 613304/s 1% 1% -- -45%
common 1113476/s 83% 83% 82% --
Rate tr so s common
tr 595781/s -- -4% -5% -44%
so 619376/s 4% -- -1% -42%
s 626447/s 5% 1% -- -42%
common 1071850/s 80% 73% 71% --
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>