On Tuesday, April 30, 2002, at 05:27 , Robert Beau Link wrote:
[..]
> #!/usr/bin/perl -w
>
> use strict;
>
> print "Number, please...";
> $alpha = <STDIN>;
> print "Another, please...";
> $beta = <STDIN>;
> $sum= $alpha + $beta;
> $diff = $alpha - $beta;
> $product = $alpha * $beta;
> $quotient = $alpha / $beta;
> $remainder = $alpha % $beta;
> $exponent = $alpha ** $beta;
> #Show it
> print "Sum: $sum\nDiference: $diff\nProduct: $product\n";
> print "Quotient: $quotient\nRemainder: $remainder\nExponent:
> $exponent\n";

Good point - another place where getting this into the online docs
would be a good thing to get done.... { I always get bit trying
to remember how to do the pragma 'no strict refs' } - the canonical
source is the 3rd Edition of Programming Perl - the index of which
lists this pragma as referenced ppp 15,56,137,263,871

{ you will also find that ch 33 is devoted to the error messages. }

there are actually a series of things that come with 'use strict' -
one of which is guarding variables - as you notice - then there are
how subs are used/pre-declared/ and the third section has to do
with references - what is a legitimate way to reference or dereference
memory items.

the principle reason that I go with it is to make sure that folks
can start avoiding some of the basic 'silly starter errors' that
we all make - to our dying days - that are called out with strict
and point us to where - that 'get passed over' when we do not use
it and come back to bit us later...

In your case your code above:

        plan a: each time you declare a new variable in a scope
                {and yes you want to do this to know scoping} make sure
                that you prefix them with

                my $var = <thingWeDoWithIt>;
        
                or use a local() for some previously defined variable
                that needs to be isolated in this scope...

        plan b: everytime you throw in a new variable just start up
                        with my $<varNameHere> -

        plan c: 'pascal it' and have a section where you predefine them:

                use vars qw/<allYourVariablesBeMine>/;

        plan d: 'pascal it' and have a section where you do things like

                my ($var, $var2.....) = (<theInitsHere>);

cf:
http://perl.plover.com/FAQs/Namespaces.html

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to