Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: •Re: On goto

by zachlipton (Beadle)
on Mar 01, 2003 at 02:02 UTC ( #239617=note: print w/ replies, xml ) Need Help??


in reply to •Re: On goto
in thread On goto

Wow! Great. After moving the my $found; outside of the block, it works great. Thanks!

Btw as a side note, why do you hate = undef? Redundant?


Comment on Re: •Re: On goto
Select or Download Code
•Re: Re: •Re: On goto
by merlyn (Sage) on Mar 01, 2003 at 02:05 UTC
    I dislike the "= undef" for two reasons:
    1. It's wrong when applied to initializing empty arrays and hashes, so it doesn't "scale" well.
    2. I presume a knowledge of people reading my code equal to that contained in my Learning Perl book, and in there, it's clear that a new scalar starts with undef

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      What are your thoughts on using it in constructors of hash or array based objects for purposes of clarity?

      For example:

      sub new { my ($class) = @_; my $this = bless {}, $class; $this->{foo} = undef; $this->{bar} = undef; return $this; }

      Where 'foo' and 'bar' may be initialized during the course of the program, but not at construction. To me, this makes it more clear what an instance of this class consists of. It also can make debugging easier if you are fond of Data::Dumpering as I am.


      "The dead do not recognize context" -- Kai, Lexx
        That seems to be more than a simple declaration, and the semantics would obviously change if you eliminated that line. I don't consider that an equivalent to my "no = undef" principle.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

        I prefer:
        sub new { bless { foo => undef, bar => undef, }, shift; }
        That may be golfing it too far for your tastes, but the point is still valid. Creating the data structure with the data you want already in it is generally clearer than creating it and then building it up with fixed assignments.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://239617]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-11-26 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls