On Sun, 2007-07-08 at 15:43 -0700, Paul Lalli wrote:
> On Jul 8, 1:25 pm, [EMAIL PROTECTED] (Kilaru Rajeev) wrote:
> > On 7/8/07, Ken Foskey <[EMAIL PROTECTED]> wrote:
> > > On Sun, 2007-07-08 at 22:27 +0530, kilaru rajeev wrote:
> > > > Please explain me whats wrong with the following code as it is
> > > > respondingwith the some errors.
> >
> > > > #!/usr/bin/perl -w
> > > > use strict;
> >
> > > # Since you are use strict you must declare all variables before
> > > # using them.  This prevents typos.
> >
> > > my ($var1, $var2);
> >
> > > > $var1 = 'Hello World'; # always wanted to do that :-)
> > > > $var2 = "$var1\n";
> > > > print $var2;
> > > > exit;
> > I have removed the *strict.*
> 
> NO NO NO.  *Keep* 'use strict'.  *FIX* the errors!
> 
> But, got the output like this:
> >
> > Name "main::varl" used only once: possible typo at sample.pl line 3.
> > Name "main::var1" used only once: possible typo at sample.pl line 2.
> 
> Perl is telling you exactly what's wrong.  Why aren't you listening to
> it?  If you had kept `use strict`, and FIXED the errors by declaring
> the variables you intended to use, Perl would have instantly told you
> WHICH variables had the typo.  As it is, with only warnings enabled,
> all Perl can do is tell you that you have a possible typo on each of
> those lines, because it doesn't know which once you *meant* to use!
> 
> 
> To use an analogy I saw in comp.lang.perl.misc recently: `use strict`
> is like the Check Engine light in your car.  When it lights up, do you
> find and fix the problem with your car, or do you disconnect the wire
> that lets the light turn on?
> 
> Paul Lalli

This exact error is why you use strict.

var1 is not varl  and it is incredibly hard to see with the wrong font.
If you declare var1 and then use varl then perl will error,  without
strict it will warn and you could miss the message (and the next when
value is undefined.  Then it goes into production and an untested path
happens.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to