________________________________________ From: Rob Dixon [rob.di...@gmx.com] Sent: 09 November 2012 17:17 To: beginners@perl.org Cc: Nemana, Satya Subject: Re: variable definition error not caught when using strict and warnings
On 09/11/2012 17:08, Nemana, Satya wrote: > Hi > > I am a little confused with this program > > Program: > use strict; > use warnings; > > if ($999 == 1056) > { > print ("\nequal"); > } > else > { > print ("\nnot equal"); > } > > What I expect: Perl to throw me an error as $999 variable is not defined, but > perl executes the code with a warning.(I don't expect the code to compile at > all) > > Output: > Use of uninitialized value in numeric eq (==) at wrong1.pl line 4. > > not equal > > > However, if I replace $999 with $num (which is not defined or initialized), I > get the following error > > Global symbol "$num" requires explicit package name at wrong1.pl line 4. > Execution of wrong1.pl aborted due to compilation errors. > > What is happening with the top program? Hello Satya The variable $999 holds the 999th capture from the most recent regular successful expression match. Since you have no regular expressions in the program it is left undefined. It would be very unusual to have so many captures in a regex but Perl does support it. Rob Hi Rob Thank you. I will give a read of the perl regular expression manual. Actually $999 resulted in a typo was i wanted to compare another variable with 999. Not from a regular expression. But it took a while for me to find the culprit as the intended code was never hit. I was trying to understand why I never got an error during the compile itself. Thanks for answering. Regards, Satya -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/