my @bla = map{ tr/h//d; $_ } @{\@arr};
Your @{\...} does nothing. You surely meant
my @bla = map{ tr/h//d; $_ } @{[@arr]};
# ^ ^
| [reply] [d/l] [select] |
You surely meant
You're correct.
| [reply] |
> my @bla = @arr; tr/h//d for @bla;
already mentioned in the OP
> my @bla = map{ tr/h//d; $_ } @{\@arr};¹
that's a nice one! 8)
But maybe my (updated) alternative is easier to read (?):
my @bla = map{ tr/h//d; $_ } map {$_} @arr;
UPDATE:
¹) as tye pointed out it should be @{ [@arr] } | [reply] [d/l] [select] |
> 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.
| [reply] [d/l] |
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
| [reply] [d/l] |