> -----Original Message-----
> From: James Edward Gray II [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, 28 February 2004 6:27 AM
> To: Gary Stainburn
> Cc: [EMAIL PROTECTED]
> Subject: Re: Trainset - initial release
> 
> On Feb 27, 2004, at 8:32 AM, Gary Stainburn wrote:
> 
> > Hi folks,
> 
> Howdy.
> 
> Okay, let's cover some basic syntax nit picks first.
> 
> 1.  Don't call subs with &debug.  That has special meaning that could 
> get you into trouble one of these days.  Stick with debug().

Watch out for examples from perl 4 which *needed* the '&'.  Nowadays it
probably doesn't do exactly as you imagine.

> 2.  I prefer $self->{_BLOCKS}= { }; to 
> %{$self->{_BLOCKS}}=();.  It's a 
> little less noisy.

Also more correct :-)   Why dereference a HASH reference and assign a
LIST
to it, when you could assign a HASH reference to a HASH reference.

> 3.  Just FYI, if you're trying to use a consistent case with 
> something 
> like $dir=uc($dir);, lc() is usually preferable to uc().  Uppercase 
> isn't as consistent in some dialects, so it makes your code more 
> portable.

Never thought of that.  Owe you one here!

> 4.  Don't nest subs.  They don't work like that, so don't 
> show it like 
> that.

[ I couldn't find nested sub's in the source. ? ]

Subs do nest.  Just not the way you expect.

Its not true 'namespace nesting' like in C++ where
the nested function is actually Parent::child(), but
scope nesting which is afaik unique to perl and 
while very powerful, also rather freaky.

-------------- SAMPLE -------------------
sub jack
{
        my $v;

        sub jill
        {
                my $j = shift;
                print "jill: v = $v".$/;
                print "jill: j = $j".$/;
                print "jill:total = ".($v+$j).$/;
        }

        $v = shift;
        print "jack:v is now $v".$/;
}

jill 3;
jack 2;
jill 3;
jack 5;
jill 3;
---------------- OUTPUT -----------------
jill: v =
jill: j = 3
jill:total = 3

jack:v is now 2
jill: v = 2
jill: j = 3
jill:total = 5

jack:v is now 5
jill: v = 2             <---- v is 2? why is it not 5?
jill: j = 3
jill:total = 5
-----------------------------------------

Its an example of closure, and tends to make my brain hurt,
so don't nest unless you mean it :-)

> Good luck.

ditto.

> 
> James
> 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to