super geek question

C. Abney cabney at cyberpass.net
Sat Feb 5 15:21:09 CST 2000


~sdpm~
On Sat, 5 Feb 2000, Eugene Tsyrklevich wrote:

> your first "solution" can be rewritten as
> 
> @flist = map +(split)[-1], @flist;
>
> your second solution can be rewritten as (notice no tilda after the equal sign)
> 
> @flist = map /(\S+$)/, @flist;

These are both great!  Wow you fixed my code and eliminated my problems
at the same time.  I've been poking around in the less traveled sections
of Perl thinking I would be rewarded:

(3)[1259]$ tar tvfz ~/downloads/pbs/pbs_v2.2p7.tar.gz | ./bm-tarout.plx 
Benchmark: timing 1000 iterations of COD1, CODE, LOOP, REG1, REGX...
      COD1: 24 wallclock secs (24.00 usr +  0.01 sys = 24.01 CPU)
      CODE: 27 wallclock secs (27.39 usr +  0.00 sys = 27.39 CPU)
      LOOP: 19 wallclock secs (18.66 usr +  0.00 sys = 18.66 CPU)
      REG1: 17 wallclock secs (17.22 usr +  0.00 sys = 17.22 CPU)
      REGX: 28 wallclock secs (27.82 usr +  0.00 sys = 27.82 CPU)

Now I know how badly my code sucks, but less why I should be poking around
in the less traveled sections of perl!  I applied Eugene's match to a
standard loop and it is virtually as fast as 'map'.

Well, now my problems don't exist in Eugene's code, but I'm still curious
about the second one:  turn warnings on and Perl will bitch about applying
a regex substitution to the /scalar/ context of the array.  This is just
not true (I think) and I was hoping someone could explain whether this is
really a bug or if my code is just really brain-damaged but Perl is doing
a pretty good job of covering for me.

Thanks again for the input and I hope someone else got as much out of this
as me <g>

====================================================================
#! /usr/bin/perl
use Benchmark;
my ( @a, @b, @c, @d, @e, @f );
@fl = <>;
timethese( 500, {
  CODE  => sub { @a = @fl; @a = map { split /\s+/; $_[$#_] } @a },
  COD1  => sub { @b = @fl; @b = map +(split)[-1], @b },
  REGX  => sub { @c = @fl; @c =~ map { s/^.*\s([\S]+)$/$1/ } @c },
  REG1  => sub { @d = @fl; @d = map /(\S+$)/, @d },
  LOOP  => sub { @f = @fl; for ($i=0;$i<@f;$i++) {$f[$i]=~ /(\S+$)/;} }
});
====================================================================

CA
-- 
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein.  -- Larry Wall                                     C. Abney

~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list