Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Adding Default Values [for BEGINNERS]

by ikegami (Patriarch)
on Dec 21, 2006 at 22:52 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://591214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found