Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: When warnings get in the way

by Old_Gray_Bear (Bishop)
on Apr 22, 2005 at 17:05 UTC ( [id://450495]=note: print w/replies, xml ) Need Help??


in reply to When warnings get in the way

my $foo = " ";
Add six characters, three of them blank; there you go. It's not much of an effort, but in six months the maintenance programmer (and that might be you) is going to appreciate it.

By initializing the variable to a known state, you have told the Maintainer what you thought about the potential values that $foo can contain, and explicitly selected one of them as the default. Developers who think about the small things are more likely to be thinking about the bigger issues as well. It has been my unfortunate experience that people who do not initialize their variables often have other unpleasant coding habbits.

----
I Go Back to Sleep, Now.

OGB

Replies are listed 'Best First'.
Re^2: When warnings get in the way
by davidrw (Prior) on Apr 22, 2005 at 17:15 UTC
    That (and there was a similar suggestion above as well) doesn't help his problem.
    my $foo = ' '; # or my $foo = ''; $foo = getFoo(); if ( $foo eq "true" ){ ... } # this will warn if $foo is undef $foo = $dbh->selectrow_array("select x from blah limit 1"); if ( $foo eq "true" ){ ... } # this will warn if $foo is undef
    In these cases, the original default value doesn't matter because it's overwritten later by a 'third party' (some sub or dbh call), and the hint to the Maintainer doesn't help cause it's something else (e.g. some db value) that's being stored.

      $foo = getFoo() || "";

      I really need to start paying attention.
      -derby

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found