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

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

Expand Messages
  • Franki
    Excellent,, I have a huge script spread over several pl files, what I am going to try adding use strict too,, gonna be fun as there are thousands of variables
    Message 1 of 8 , May 4, 2001
    • 0 Attachment
      Excellent,,

      I have a huge script spread over several pl files, what I am going to try
      adding use strict too,, gonna be fun as there are thousands of variables in
      it, some global, some local.....
      and I'll bet a fair number of them were not declaired before being used....

      gonna be joy,, but will most likely be handy to know it is right at the
      end...

      thanks heaps...

      rgds

      Frank

      -----Original Message-----
      From: J.E. Cripps [mailto:cycmn@...]
      Sent: Friday, 4 May 2001 4:35 PM
      To: perl-beginner@yahoogroups.com
      Subject: RE: [PBML] "use strict" and "$my total"



      > Can someone in brief tell me the difference between -T or taint and use
      > strict????

      The -w option and "use strict" pertain to Perl programming universally

      -w turns warnings on. A lot of problems that would pass undetected
      without it, e.g. uninitialized variables, are announced when they are
      encountered: perldoc -q debug

      "use strict" turns on compile time warnings, disallowing global variables
      among other things that can cause trouble, and ensuring that
      variables are referred to by their proper names: perldoc strict

      -T pertains to CGI scripts. turns on taint checking. It prevents data
      from outside the script from affecting anything outside the script:
      perldoc -q taint. See also: perldoc perlsec.

      There's more about tainting in the World Wide Web Security FAQ:
      Q45: What are Perl taint checks? How do I turn them on? and
      later in the same FAQ for untainting variables.

      CGI.pm also rates a mention, since it has become the favored way to program
      CGI in Perl since this module was written: perldoc cgi

      > if a script is already -T does it need use strict? can they be used
      > together???

      Yes indeed. JEC.





      Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    • 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 2 of 8 , May 4, 2001
      • 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 3 of 8 , May 4, 2001
        • 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.