Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

If you want to understand what's going on, you can try adding some print statements. This should make it pretty clear what's happening.
use strict; my @list = qw(1 2 3 4 5); my $each = ""; my $i = 0; my @newlist = (); foreach $each (@list) { print "Each was: $each\n"; #new $each *= 2; print "Each is: $each\n"; #new $newlist[$i] = $each; print "New list is: $newlist[$i]\n"; #new print "Old list is $list[$i]\n\n"; #new ++$i; } for ($i= 0; $i<5; ++$i) { print ($newlist[$i] - $list[$i], "\n"); }
And maybe in the future it would be a good idea for the reason for what happens to be included in the 'black box of enlightenment' so that people won't just be puzzled, but will learn, too? (Or maybe not; it's good debugging practice to figure out where the unexpected happens. Why have the box at all? There isn't much point to just show the output, since people can just run the program to see the output.)

In reply to (kudra) Re2: NEWBIE Brain Teaser by kudra
in thread NEWBIE Brain Teaser by nysus

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (8)
    As of 2014-12-27 16:17 GMT
    Find Nodes?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?

      Results (177 votes), past polls