Debugging Practice
Bill Jones
bill at fccj.org
Thu Jun 10 20:13:01 CDT 1999
On the Jax.PM jacksonville-pm-list;
"Bill Jones" <bill at fccj.org> wrote -
> 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 :) ...
>
Neither is me :)
> 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.
>
That's a one way; usually at first glance
(some disagree, however...)
> 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.
Super; another way. Yes, do{} would work as well.
OK, as I collect more ways to do this,
we shall see who picked the way I
picked (not that I am right or anything,
this was just a simple exercise...)
Saturday I'll post the accumulative answers
for all to see and contemplate...
Enjoy!
-Sneex- :]
_________________________________________________________________________
Bill Jones | Data Security Specialist | http://www.fccj.org/cgi/mail?dss
FCCJ | 501 W State St | Jacksonville, FL 32202 | 1 (904) 632-3089
$_="Jacksonville Perl Mongers";while(/([Jacksonville Perl Mongers])/g){
print join(" ",map{defined $_ ? $_ : ""}$`,$&,$',$+),"\n";}
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