Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: ($_) use warnings and uninitialized variables

by mt2k (Hermit)
on Nov 22, 2002 at 23:08 UTC ( #215285=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Programming guidelines/rules
in thread Perl Programming guidelines/rules

If warnings are turned on you are warned about uninitialized values, aren't you?
That's one of the points of use warnings. If you are using uninitialized variables all over the place, then perhaps a review of the code is necessary. Below I have thrown together an example of two scripts that do the exact same thing... except that one produces warnings and one doesn't :)

#!/usr/bin/perl # The 'bad' version - produces warnings use strict; use warnings; my $name; # perhaps some code to get user's name # { ... } print 'My name is ' . $name;
#!/usr/bin/perl # The 'good' version - produces no warnings use strict; use warnings; my $name; # perhaps some code to get user's name # { ... } # The key line. Set a default value, even if blank. $name ||= ""; print 'My name is ' . $name;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-08-14 01:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?