Debugging Practice

Steve Lane sml at zfx.com
Thu Jun 10 15:27:19 CDT 1999


On the Jax.PM jacksonville-pm-list;
Steve Lane <sml at zfx.com> wrote -


Bill Jones wrote:
> At any rate, here is a practice script for you
> 'less-than-expert' perl'ers to debug:
> 
> #Reducing the problem to smallest test code:
> $vFlag = "a|0|0|y|0|0|x|x|z";
> 
> print
>       " Well? ",
> {
>     ((split(/\|/, $vFlag))[7] eq 'x') ? 'do this' : 'do that'
> },
>       "\n";

i don't consider myself an 'expert', so i guess
i can try :) ...

print() takes a list of scalars.  you're giving it
three of them.  the second is the thing that looks
like a block, but is not a block; a braced expression
in scalar context is an anonymous hash reference.
the value of this when printed is the string "HASH"
followed by the memory address the reference points
to, giving the output:

 Well? HASH(0x8051118)

one fix is to remove the braces completely; they're
not needed.  that's what i'd do.

another one would be to add a "do" in front of the
opening brace; this forms a do-block that is like a
function that returns the value of the last executed
statement.  
--
Steve Lane <sml at zfx.com>


The Jacksonville Perl Monger's Group is operated by -
Bill -Sneex- Jones ( sneex at usa.net ),
to whom send all praises, complaints, or comments...




More information about the Jacksonville-pm mailing list