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

setup wrong?

Expand Messages
  • Bill Walton
    I m wondering if I have perl installed correctly. The script below prints Hello world! , and *only* that. #!/usr/bin/perl -w use warnings; $TestString= Hello
    Message 1 of 4 , Dec 5, 2005
      I'm wondering if I have perl installed correctly.

      The script below prints 'Hello world!", and *only* that.

      #!/usr/bin/perl -w

      use warnings;

      $TestString="Hello world!\n";
      print "$TestString";

      The same script, adding "use strict;" above "use warnings;" prints error messages and aborts execution "due to compilation errors."

      The results I'm getting with "use strict:" are:

      Global symbol "$TestString" requires explicit package name at UseStrictTest.plx line 6.
      Global symbol "$TestString" requires explicit package name at UseStrictTest.plx line 7.
      Execution of UseStrictTest.plx aborted due to compilation errors.

      Do I have something set up wrong? Am I not doing something I should be doing?

      Thanks in advance for your help.

      Best regards,
      Bill

      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Bill I m wondering if I have perl installed correctly. Bill The script below prints Hello world! , and *only* that. Bill #!/usr/bin/perl -w Bill use
      Message 2 of 4 , Dec 5, 2005
        >>>>> "Bill" == Bill Walton <bill.walton@...> writes:

        Bill> I'm wondering if I have perl installed correctly.
        Bill> The script below prints 'Hello world!", and *only* that.

        Bill> #!/usr/bin/perl -w

        Bill> use warnings;

        Bill> $TestString="Hello world!\n";
        Bill> print "$TestString";

        Bill> The same script, adding "use strict;" above "use warnings;" prints error messages and aborts execution "due to compilation errors."

        Exactly as expected. "use strict" says "I will now declare my variables",
        and you didn't have a "my" in front of the first appearance of $TestString.

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • J.E. Cripps
        ... When you included the use strict pragma variables must be declared via use vars or localised via my or be fully-qualified (package name) URL:
        Message 3 of 4 , Dec 5, 2005
          > The same script, adding "use strict;" above "use warnings;"
          > prints error messages and aborts execution "due to compilation errors."


          > The results I'm getting with "use strict:" are:

          > Global symbol "$TestString" requires explicit package name at UseStrictTest.plx line 6.
          > Global symbol "$TestString" requires explicit package name at UseStrictTest.plx line 7.
          > Execution of UseStrictTest.plx aborted due to compilation errors.

          > Do I have something set up wrong? Am I not doing something I should be doing?

          When you included the "use strict" pragma
          variables must be declared via "use vars" or
          localised via "my" or be fully-qualified (package
          name)

          URL: http://www.perl.com/doc/manual/html/lib/strict.html
          Linkname: strict - Perl pragma to restrict unsafe constructs

          I first looked this up via "perldoc -q strict"
          which didn't find anything! Does anyone know
          the perdoc cite for "use strict" ... I know
          I've read it somewhere.

          It's a good idea to always "use strict"
        • acummingsus
          ... errors. [ . . ] ... [ . . ] ... perldoc name_of_perl_module (case sensitive IOW case must match that of module s actual case) perldoc strict
          Message 4 of 4 , Dec 5, 2005
            --- In perl-beginner@yahoogroups.com, "J.E. Cripps" <cycmn@n...> wrote:
            > > The same script, adding "use strict;" above "use warnings;"
            > > prints error messages and aborts execution "due to compilation
            errors."
            [ . . ]
            > When you included the "use strict" pragma
            > variables must be declared via "use vars" or
            > localised via "my" or be fully-qualified (package
            > name)
            [ . . ]
            > I first looked this up via "perldoc -q strict"
            > which didn't find anything! Does anyone know
            > the perdoc cite for "use strict"

            perldoc name_of_perl_module

            (case sensitive IOW case must match that of module's actual case)

            perldoc strict

            http://perldoc.perl.org/index-pragmas.html

            http://perldoc.perl.org/strict.html

            http://learn.perl.org/

            --
            http://www.perl.com/pub/a/2001/01/begperl6.html

            Strict vars

            (relevant here, that heading is near half way down that page)
            --

            http://www.google.com/search?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=perl+pragma+strict&btnG=Search

            But:

            use discretion; # not really such a module as that
            print "because that searches the entire internet";

            (the O'reilly site I included (used discretion) is known).

            --
            Alan.
          Your message has been successfully submitted and would be delivered to recipients shortly.