Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] "use strict" and "$my total"

Expand Messages
  • Don Smith
    Thanks for the help and the strict lesson J.E. :-) I d love to be competent enough with PERL to offer others help, but I m not there yet, so I pay it
    Message 1 of 8 , May 4 5:18 PM
    • 0 Attachment
      Thanks for the help and the "strict" lesson J.E. :-)

      I'd love to be competent enough with PERL to offer others help, but I'm not
      there yet, so I "pay it forward" in other ways. But I do keep the spirit
      alive.

      Cheers,

      Don Smith


      ----- Original Message -----
      From: "J.E. Cripps" <cycmn@...>
      To: <perl-beginner@yahoogroups.com>
      Sent: Friday, May 04, 2001 1:49 AM
      Subject: [PBML] "use strict" and "$my total"


      >
      > Here's a few words on "use strict" Now you have been warned :-)
      >
      > "anything that exceeds 10 lines or 10 minutes of use must "use strict" "
      > -- Randal Schwarz
      >
      > If you let it, Perl will generate incredibly useful messages and
      > warnings. Invoke Perl with the -w switch to enable warnings and include
      > "use strict" in your program to guard against unsafe practices.
      >
      > One of the three strictures of "use strict" is enforcing explicit
      > declaration of variables. This means that one can't just use a variable as
      > one might have been accustomed to do, just by naming it.
      >
      > There are several ways of pre-declaring variables. One can declare a
      > private variable with "my":
      >
      > my $total;
      >
      > This is what I did in the recent reply to Don. Note that "my"
      > variables can only be plain scalars, hashes or arrays. And "my" variables
      > are private variables. They have meaning and can be seen and used only in
      > the block of code in which they are declared. Another term for private is
      > "lexically scoped."
      >
      > "use strict" prevents accidental use of globals, because global
      > variables are dangerous: any piece of your code can access and change
      > their values, possibly by accident.
      >
      > "Variable scoping - some people get it, some people don't. I wish the
      > people that don't get it would stay out of writing code, or especially
      > sharing code."
      > -- Randal Schwartz
      >
      > Here's one msg seen when a variable isn't declared and "use strict"
      > is in force:
      >
      > Global symbol "$perm" requires explicit package name at myprog.pl line 29.
      >
      > The pragma "use strict" checks that all variables you use are either
      > Perl's globals,(@INC), fully-qualified globals ($Foo::bar), predeclared
      > globals (with use vars or our()), or declared private (with my()). So to
      > eliminate the msg, you'll have to do one of these. "my" is often what you
      > want, even though the msg speaks of "global symbols."
      >
      > There are few things that a high-performance program will want to do
      that
      > "use strict" prevents, and even so, it can be disabled for any chunk of
      code
      > in a controlled fashion.
      >
      > The two other official strictures of "use strict" apply to references
      > and subroutines, see perldoc strict (but not perldoc -q strict) Not in the
      > perldocs, but part of the culture, is that any post to a USENET Perl
      > newsgroup should "use strict."
      >
      > This msg based on USENET posts by: Tom Phoenix (rootbeer@...),
      > Gary Ebert (gary@...) Randal L.Schwartz (merlyn@...) and
      > http://www.jepstone.net/papers/PerlInside/slide23.html Perl Inside,
      PerlInside 23: 20 Minutes: Warnings and use ... Jepson
      > http://prometheus.frii.com/~gnat/yapc/2000-stages/slide26.html YAPC 2000,
      Stages of a Perl Programmer 26: use strict
      >
      >
      >
      >
      >
      >
      >
      >
      >
      > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
      >
      >
    • vallinis@yahoo.com
      Wow that was a good post indeed! Descriptive, deep, and geared towards persons who do not have a thorough understanding of perl (some post are quite brief and
      Message 2 of 8 , May 4 6:25 PM
      • 0 Attachment
        Wow that was a good post indeed! Descriptive, deep, and geared
        towards persons who do not have a thorough understanding of perl
        (some post are quite brief and so on the topic that a beginner sees
        them, really, as post for advanced progammers...). I do not want to
        waste our forum bandwidth, but my congratulations for this post
        appeared mandatory to me! Thank you!

        --- In perl-beginner@y..., "J.E. Cripps" <cycmn@n...> wrote:
        >
        > Here's a few words on "use strict" Now you have been warned :-)
        >
        (... snip...)
      Your message has been successfully submitted and would be delivered to recipients shortly.