in reply to Re^2: non aliased default var $_
in thread non aliased default var $_

> my @bla = @arr; tr/h//d for @bla;

already mentioned in the OP

Sorry. I missed that. But then, that makes me wonder why you are seeking an alternative to it?

From my perspective, it's a no brainer. On my system, the first alternative runs in 1/64th of the time and uses half the memory to your double map solution;

C:\test>perl -MTime::HiRes=time -wE"my @a= 0..1e6; my $t= time;my @bla= @a; tr[0][]d for @bla; say tim +e-$t; <>" 0.488373041152954 C:\test>perl -MTime::HiRes=time -wE"my @a= 0..1e6;my $t= time;my @bla= map{tr/h//d; $_}map{$_} @a;say +time-$t; <>" 32.5820000171661

I realise that you may not work with million element arrays very often, but getting into good habits will save you grief when you are. And it just so much clearer.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

Replies are listed 'Best First'.
Re^4: non aliased default var $_
by LanX (Saint) on Mar 10, 2010 at 13:26 UTC
    > But then, that makes me wonder why you are seeking an alternative to it?

    I'm meditating more about orthogonal code than speed.

    But you are really measuring strange things on your sytsem

    lanx@ubuntu:~$ perl -MTime::HiRes=time -e'my @a= 0..1e6;my $t= time;my + @bla=@a; tr/h//d for @bla;print time-$t; <>' 2.48298692703247 lanx@ubuntu:~$ perl -MTime::HiRes=time -e'my @a= 0..1e6;my $t= time;my + @bla= map{tr/h//d; $_} @{\@a};print time-$t; <>' 7.50910615921021 lanx@ubuntu:~$ perl -MTime::HiRes=time -e'my @a= 0..1e6;my $t= time;my + @bla= map{tr/h//d; $_}map{$_} @a;print time-$t; <>' 8.25657296180725

    Cheers Rolf

      you are really measuring strange things on your sytsem

      Yeah :( It seems to the result of a conflict between 64-bit perl 5.10, and the MS runtime. I get a much smaller differential with 32-bit 5.8.8, but it's still not great:

      C:\test>\perl32\bin\perl -MTime::HiRes=time -we"my@a=0..1e6;my$t=time; +my@bla=@a; tr[0][]d for @bla;print time-$t; <>" 0.638000011444092 C:\test>\perl32\bin\perl -MTime::HiRes=time -we"my@a=0..1e6;my$t=time; +my@bla=map{tr/h//d;$_}map{$_}@a;print time-$t; <>" 9.05199980735779

      But every test I tried using malloc()/free() from the 64-bit MS runtime using C seem to fly. Course, it'd be easier to track down if you could get some feedback on these issues, but that's never forthcoming.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.