Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Adding Default Values [for BEGINNERS]

by ikegami (Pope)
on Dec 21, 2006 at 22:52 UTC ( #591214=note: print w/replies, xml ) Need Help??


in reply to Adding Default Values [for BEGINNERS]

$file0 is not blank. It contains \n. Just use chomp to remove the newline before checking if the variable is "empty".

my $file = <STDIN>; chomp($file); $file ||= "somelist";

The above will also use the default if 0 (zero) is entered. The following avoids that problem:

my $file = <STDIN>; chomp($file); $file = "somelist" if not length $file;

By the way, you really, really, really should use use strict; and use warnings;.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2021-06-12 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (53 votes). Check out past polls.

    Notices?