Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2018-06-21 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (119 votes). Check out past polls.

    Notices?