http://qs321.pair.com?node_id=215285


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;