Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Little annoying mistakes ... of others

by Limbic~Region (Chancellor)
on Dec 06, 2008 at 22:34 UTC ( #728606=note: print w/replies, xml ) Need Help??

in reply to Little annoying mistakes ... of others

I am sure I could come up with a laundry list but my mind is on other things (family isn't feeling well). The one that bugs me is not considering defined values that evaluate to false when setting up a conditional. Since I am guilty of this, let me give an example:
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] or die "Usage: $0 <input_file>"; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $ +!";

While I think it is uncommon that someone would name their file '0', it is possible. In other examples, the oversight might be the empty string ''. As a reference, see True and False (aka Booleans). I know that 5.10 introduced the // operator which is great.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Little annoying mistakes ... of others
by toolic (Bishop) on Dec 07, 2008 at 02:59 UTC
    Along the sames lines, and much more likely, is to pass in a numeric option on the command line whose value is quite probably 0. For example, I have a histogram script in which I can pass in the minimum value. Unless I check the value using defined, the thing just doesn't work right:
    use strict; use warnings; use Getopt::Std; our $opt_m; getopts('m:'); print "$opt_m\n" if ($opt_m); # Wrong #print "$opt_m\n" if (defined $opt_m); # Right

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://728606]
[ww]: OTOH, -- for ads suggesting that being good at games is somehow eq "greatness"
[ambrus]: 1nickg: obviously the gamers don't know. but anyway, I need the whole room backlit, because watching a monitor in a dark room (like many people do) is tiring for my eyes, even more so than doing it in a lit room.
[1nickt]: ambrus I agree. I suspect one's eyes are always trying to adjust across the boundary between very bright and very dark ... like a camera's autofocus struggling to choose the target.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (15)
As of 2017-03-27 13:58 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.