in reply to Check your wits

Uhm, what's so exiting about it? You're dumping @values before it has had a chance to be initialized (the variable exists, it was defined at compile time, but the assignment hasn't happened, as at run time, it hasn't gotten past the assignment yet - and in fact, it never will).

Replies are listed 'Best First'.
Re^2: Check your wits
by dHarry (Abbot) on Aug 08, 2008 at 15:02 UTC

    "Obviously" the script is flawed, but the real question is did you see it before you ran the script or afterwards:-)

    For the record: I did afterwards:-/ Gestalt Principles of Perception?

      Before. I took the approach of identifying difference with what I would do. I immediately saw two things: code before functions, and use of exit. I looked if there was more code below exit, and voila!

      The fix is to add one word:

      #!/usr/bin/perl use strict; use warnings; use Data::Dumper; _test(); exit; ######## subroutines BEGIN { <----- my @values = qw( 1 2 3 ); sub _test { print "Values:\n", Dumper( \@values ); } }
      I saw it before I ran the script. But obviously, from how the question was framed, I knew in advance there was something fishy. And the shortness of the code didn't leave many options of what would be wrong.

      Would I have seen it if the program was larger, and it wasn't flagged as "there's something going on here"? Probably not.

      I didn't see it because I was expecting some closure pitfall and was searching for that to the exclusion of everything else.