Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: compare arrays numbers

by ikegami (Pope)
on Feb 16, 2010 at 19:13 UTC ( #823533=note: print w/replies, xml ) Need Help??


in reply to Re^2: compare arrays numbers
in thread compare arrays numbers

$a[$_] -= $b[$_] for 0..$#a;
is optimised into a counting loop (O(1) memory).
$a[$_] -= $b[$_] for (),0..$#a;
is not optimised (O(N) memory).

but 0..$#a is a list anyway

".." is usually the range operator, but not in the first example. In fact, it's not an operator at all there. It's just a separator like the semicolons in for(;;).

$ perl -MO=Concise,-exec -e'1 for (),$x..$y' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <;> nextstate(main 1 -e:1) v:{ 4 <0> pushmark sM 5 <|> range(other->6)[t3] lK/1 \ 6 <#> gvsv[*y] s | 7 <1> flop lKM | Range op called goto 8 | to produce a list. f <#> gvsv[*x] s | g <1> flip[t4] lK / 8 <#> gv[*_] s 9 <{> enteriter(next->a last->d redo->a) lK/8 b <0> iter s c <|> and(other->a) vK/1 a <0> unstack v goto b d <2> leaveloop vK/2 e <@> leave[1 ref] vKP/REFC -e syntax OK $ perl -MO=Concise,-exec -e'1 for $x..$y' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v:{ 3 <;> nextstate(main 1 -e:1) v:{ 4 <0> pushmark s 5 <#> gvsv[*x] s \ Args for enteriter/S 6 <#> gvsv[*y] s / 7 <#> gv[*_] s 8 <{> enteriter(next->9 last->c redo->9) lKS/8 a <0> iter s b <|> and(other->9) vK/1 9 <0> unstack v goto a c <2> leaveloop vK/2 d <@> leave[1 ref] vKP/REFC -e syntax OK

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://823533]
help
Chatterbox?
[Discipulus]: Tanktalus my comment was about how to fork & join in tk?
[marioroy]: Oh, I've might of missed Discipulus's earlier response. I had gone to bed.
[Tanktalus]: ah, I don't even have the perlmonks site open in my browser :)
Tanktalus is chatting through his cbstats application :)
[marioroy]: Perl is so much fun.
[Discipulus]: Tanktalus i recently started a Meditation about marioroy's MCE suit of modules, but is even better to see a practical question answered than responses to my meditation
[Discipulus]: good night mario!
[Tanktalus]: yeah, I saw you post about MCE - the concept looks really really cool. I wonder how well it plays with Coro :)
[Lady_Aleena]: Hi guys. I asked this earlier but got no answer. Why is this dying at -exec: my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;);
[Lady_Aleena]: The error find: missing argument to `-exec'

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2017-04-23 19:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.