Prev: FAQ 8.5 How do I read just one key without waiting for a return key?
Next: FAQ 4.55 How do I process an entire hash?
From: Peng Yu on 20 May 2010 18:16 I'm puzzled why I can not use the first line below. Would you please let me know how write it such that the if clause is at the beginning rather than at the end. if(defined $opt_o) print "$opt_o\n"; print "$opt_o\n" if defined $opt_o; Regards, Peng
From: sisyphus on 20 May 2010 18:47 On May 21, 8:16 am, Peng Yu <pengyu...(a)gmail.com> wrote: > I'm puzzled why I can not use the first line below. Would you please > let me know how write it such that the if clause is at the beginning > rather than at the end. > > if(defined $opt_o) print "$opt_o\n"; > if(defined $opt_o) { print "$opt_o\n" } Cheers, Rob
From: Dr.Ruud on 20 May 2010 19:05 Peng Yu wrote: > Would you please > let me know how write it such that the if clause is at the beginning > rather than at the end. > > if(defined $opt_o) print "$opt_o\n"; defined $opt_o and print $opt_o, $/; -- Ruud
From: Tad McClellan on 20 May 2010 21:05
Peng Yu <pengyu.ut(a)gmail.com> wrote: > I'm puzzled why I can not use the first line below. Did you look up the "if" statement in Perl's docs? perldoc perlsyn Compound Statements ... a block is delimited by curly brackets, also known as braces. We will call this syntactic construct a BLOCK ... if (EXPR) BLOCK > Would you please > let me know how write it such that the if clause is at the beginning > rather than at the end. > > if(defined $opt_o) print "$opt_o\n"; that is if (EXPR) EXPR but you need if (EXPR) BLOCK if (defined $opt_o) {print "$opt_o\n"} -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site. |