Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: When warnings get in the way

by kwaping (Priest)
on Apr 22, 2005 at 17:28 UTC ( [id://450504]=note: print w/replies, xml ) Need Help??


in reply to When warnings get in the way

As with most things in Perl, there are many ways to accomplish this task (avoiding the "uninitialized" error). Personally, the solution I use is contextual. When doing form data validation where there can be a lot of fields, and all the field names may not neccessarily be known by the programmer, I like to use the OP's method:
if ($form{$key} && $form{$key} =~ /\w+/) { # ...
However, when checking data passed to a method or subroutine, I prefer to use the ||= (aka "default") method:
my ($self,$asdf) = @_; $asdf ||= '';
Finally, in general, I try to scope, declare, and initialize my variables at the start of the program whenever possible.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2025-06-22 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.