Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(kudra) Re2: NEWBIE Brain Teaser

by kudra (Vicar)
on Apr 15, 2001 at 01:21 UTC ( #72614=note: print w/replies, xml ) Need Help??


in reply to Re: NEWBIE Brain Teaser
in thread NEWBIE Brain Teaser

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.)

Replies are listed 'Best First'.
Re: (kudra) Re2: NEWBIE Brain Teaser
by moen (Hermit) on Apr 15, 2001 at 01:39 UTC
    kudra said:
    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?

    I agree, some further explanation to the answer should be added.

    jmoen

Re: (kudra) Re2: NEWBIE Brain Teaser
by nysus (Priest) on Apr 15, 2001 at 01:39 UTC
    Thanks for the feedback. I was debating whether or not to post the solution or some kind of hint along with the answer. I'll try some different things in the future and see what seems to be the most helpful to people. For this one, I plan on posting the answer tomorrow.

    I think if people can immediately check the answer and see that their first instinct was wrong, this will tend to get them involved more and make them curious...I think they'll start wondering where they went wrong and figure it out for themselves.

    Why the black box? Just for aesthetic reasons...makes it a little more fun, I think.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://72614]
help
Chatterbox?
[Corion]: stevieb: Yeah, but I don't follow guitar players enough... I never got Prince and I don't think I could recognize his play style. I can recognize Santana and Nile Rodgers, but that's about it, and not really deep knowledge I think ;)
[stevieb]: Jeff Healey cut of My guitar gently weeps
[stonecolddevin]: you don't recognize Prince. Prince tells you it's him.
[erix]: Alvin Lee (Ten Years After) played a jazzguitar ("Big Red"), a good warm sound
[stonecolddevin]: I think Stevie Ray is one of maybe 2 or 3 people that could take a Hendrix song and make you go "...huh. this is close." https://open. spotify.com/track/ 0UVM9trirBK5s1xBwL oVhZ
[stonecolddevin]: https://open. spotify.com/track/ 0UVM9trirBK5s1xBwL oVhZ rather
[Corion]: Sadly I must go to bed now :-| See y'all!
[erix]: I really loved/love this "Recorded Live" record, 1973 (yes, I'm that old)
[stonecolddevin]: goodnight Corion
[erix]: cya Corion :)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2017-06-22 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (531 votes). Check out past polls.