Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
"be consistent"
 
PerlMonks  

Re: Adding Default Values [for BEGINNERS]

by ikegami (Patriarch)
on Dec 21, 2006 at 17:52 UTC ( [id://591214]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.