Using Strict and Warnings modules.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonniethecodeprince
    New Member
    • Mar 2007
    • 35

    Using Strict and Warnings modules.

    Hello everyone. Last Friday I finally found a good compiler for PERL and the "shebang" line I think I need to run. They might not be running on a server but certainly they compiling well on my hard drive.

    So that's great.

    [CODE=perl]
    #!C:\perl\bin\

    use strict;
    use warnings;

    $wordCount = $wordCount +1;
    $calc1 = 1+1;
    $bookTitle;
    $name = "Jonnie";
    $sentence = "Ask " . $name . " about Football";

    print "The length of the string is $wordCount\n";
    print "The second scalar returns a value of $calc1 ";
    $theLine = $_;
    print "The title of the Book is confirmed as $bookTitle\n";
    print 'The title of the Book was stored in the scalar, $bookTitle';
    print "\nwin", "dows";
    print "\n$sentenc e";
    print "\n\U$sentence" ;

    print "\nYou can contact me via email on jonniegrieve\@y ahoo.com";
    [/CODE]

    with the above code, it compiles very well but only when i do not include strict and warnings up there in the code. I've looked it up as best as i can but can anyone tell me what they do

    [code=perl]Global symbol "$wordCount " requires explicit package name at first.pl line 6.
    Global symbol "$wordCount " requires explicit package name at first.pl line 6.
    Global symbol "$calc1" requires explicit package name at first.pl line 7.
    Global symbol "$bookTitle " requires explicit package name at first.pl line 8.
    Global symbol "$name" requires explicit package name at first.pl line 9.
    Global symbol "$sentence" requires explicit package name at first.pl line 10.[/code]
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    This is a "side-effect" of the strict pragma. It forces you to define all of your variables, the first time they are used, with a preceding "my".

    So, your re-written script would look like this:

    [CODE=perl]
    #!C:\perl\bin\

    use strict;
    use warnings;

    my $wordCount = $wordCount +1;
    my $calc1 = 1+1;
    my $bookTitle;
    my $name = "Jonnie";
    my $sentence = "Ask " . $name . " about Football";

    print "The length of the string is $wordCount\n";
    print "The second scalar returns a value of $calc1 ";
    my $theLine = $_;
    print "The title of the Book is confirmed as $bookTitle\n";
    print 'The title of the Book was stored in the scalar, $bookTitle';
    print "\nwin", "dows";
    print "\n$sentenc e";
    print "\n\U$sentence" ;

    print "\nYou can contact me via email on jonniegrieve\@y ahoo.com";
    [/CODE]

    Regards,

    Jeff

    Comment

    • jonniethecodeprince
      New Member
      • Mar 2007
      • 35

      #3
      It worked. :D Thanks for your help.

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Windows ignores the shebang line. You can run a perl script with any shebang line or no shebang line on windows unless you have deliberately setup windows to read the shebang line to know where perl is. Running perl scripts as a CGI in a browser on a local sever may or maynot require the shebang line. Apache needs it be default but can be setup to find perl via a directive instead of the shebang line.

        Comment

        Working...