Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: More effective way to increase two elements of a list in parallel?

by wade (Pilgrim)
on May 06, 2008 at 18:09 UTC ( #685023=note: print w/ replies, xml ) Need Help??


in reply to More effective way to increase two elements of a list in parallel?

I see a few things, here.

First, you should always use:

use strict; use warnings; use diagnostics; # not everyone puts this in but I think it's helpful

But that's just general stuff. The big question I have is why use a while (especially with the -- eesh -- next statement) when an if is really what you want? Rewriting this using your (excellent) suggestion of the reformulated for:

foreach my $pdu_num (3 .. 8) { $pdu_num = 11 - $pdu_num unless defined $order; if (my $node = shift @nodes) { $map{$node} = $pdu . '['.$pdu_num.']'; } }

gives, I think, a much clearer chunk of code

--
Wade


Comment on Re: More effective way to increase two elements of a list in parallel?
Select or Download Code
Re^2: More effective way to increase two elements of a list in parallel?
by FunkyMonk (Canon) on May 06, 2008 at 23:05 UTC
    Note that
    if (my $node = shift @nodes) { $map{$node} = $pdu . '['.$pdu_num.']'; }

    is not the same as the OP's code. Your code won't process the if if the first element of @nodes is false. Better to use

    if (@nodes) { my $node = shift @nodes; $map{$node} = $pdu . '['.$pdu_num.']'; }


    Unless I state otherwise, all my code runs with strict and warnings

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685023]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-09-20 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls