Prev: FAQ 6.12 Can I use Perl regular expressions to match balanced text?
Next: FAQ 7.9 How do I create a module?
From: Wanna-Be Sys Admin on 19 Jan 2010 01:17 Faith Greenwood wrote: > I have the following: > > use strict; > use warnings; > > my $number=0; > print "This:$number\n"; > print "That:$number\n" if $number; > > __END__ > > Of the two lines that print the variable, why does it print the first > line but not the second? > If I change the $number to equal 1, then both lines print fine. > > thank you print "That:$number\n" if defined $number; or print "That:$number\n" if $number ne ""; -- Not really a wanna-be, but I don't know everything.
From: Ben Morrow on 19 Jan 2010 01:07 Quoth "Uri Guttman" <uri(a)StemSystems.com>: > >>>>> "BM" == Ben Morrow <ben(a)morrow.me.uk> writes: > > BM> Quoth "Uri Guttman" <uri(a)StemSystems.com>: > >> >>>>> "BM" == Ben Morrow <ben(a)morrow.me.uk> writes: > >> > BM> Quoth sreservoir <sreservoir(a)gmail.com>: > <snip, but attributions left> > > BM> I know you know that, which is why I wasn't saying it to you. I was > BM> saying it to sreservoir, who apparently didn't. > > then you should have replied to his post and not mine. :) I did. Ben
From: Peter J. Holzer on 19 Jan 2010 15:32 On 2010-01-19 02:40, sreservoir <sreservoir(a)gmail.com> wrote: > ~% perl -wle'print !1' > Use of uninitialized value in print at -e line 1. I suspect that your shell (csh?) is fooling you. If !1 is interpreted as a history expansion and command 1 was empty the command really reads: ~% perl -wle'print ' which will produce the warning you see. hp
From: Glenn Jackman on 19 Jan 2010 17:43 At 2010-01-19 03:32PM, "Peter J. Holzer" wrote: > On 2010-01-19 02:40, sreservoir <sreservoir(a)gmail.com> wrote: > > ~% perl -wle'print !1' > > Use of uninitialized value in print at -e line 1. > > I suspect that your shell (csh?) is fooling you. If !1 is interpreted as > a history expansion and command 1 was empty the command really reads: Does csh really do history expansion inside single quotes? Wow, that really is harmful. -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: Ben Morrow on 19 Jan 2010 18:22
Quoth Glenn Jackman <glennj(a)ncf.ca>: > At 2010-01-19 03:32PM, "Peter J. Holzer" wrote: > > On 2010-01-19 02:40, sreservoir <sreservoir(a)gmail.com> wrote: > > > ~% perl -wle'print !1' > > > Use of uninitialized value in print at -e line 1. > > > > I suspect that your shell (csh?) is fooling you. If !1 is interpreted as > > a history expansion and command 1 was empty the command really reads: > > Does csh really do history expansion inside single quotes? Wow, that > really is harmful. It would appear so: % csh %echo %echo '!1' echo 'echo' echo %echo "!1" echo "echo" echo %echo '\!1' !1 %exit Ben |