FAQ
All,

I added the "use strict;" statement to my script for the first time and
received the following compilation errors:
Global symbol "$LoginName" requires explicit package name at todaysFiles.pl
line 43.
Global symbol "$TMPNow" requires explicit package name at todaysFiles.pl
line 45.
Global symbol "@filenames" requires explicit package name at todaysFiles.pl
line 48.
Global symbol "$filenames" requires explicit package name at todaysFiles.pl
line 49.

This program works fine without the "use strict" statement?.please advise!!

Also, can someone offer an explanation of how "=" differs from "= ="??

Thanks In advance!


Steve Pittman
Medstar Health

Search Discussions

  • Morten Liebach at Apr 4, 2003 at 11:33 am

    On 2003-04-03 14:05:19 -0500, Steve.E.Pittman@Medstar.net wrote:

    All,

    I added the "use strict;" statement to my script for the first time and
    received the following compilation errors:
    Global symbol "$LoginName" requires explicit package name at todaysFiles.pl
    line 43.
    Global symbol "$TMPNow" requires explicit package name at todaysFiles.pl
    line 45.
    Global symbol "@filenames" requires explicit package name at todaysFiles.pl
    line 48.
    Global symbol "$filenames" requires explicit package name at todaysFiles.pl
    line 49.

    This program works fine without the "use strict" statement?.please advise!!
    Use something like:

    my $LoginName;
    my $TMPNow;

    Etc.
    Also, can someone offer an explanation of how "=" differs from "= ="??
    I suppose you meant "==" instead of "= =".

    "=" is an assignment. "==" is a comparison.

    I can recommend Learning Perl or one of the other nice beginners books,
    you wouldn't get into these things then. And use strict and warnings
    always, from the beginning of all new scripts, it helps a lot.

    Have a nice day
    Morten

    --
    OpenPGP: 0xF1360CA9 - 8CF5 32EE A5EC 36B2 4E3F ACDF 6D86 BEB3 F136 0CA9
    Morten Liebach <m@mongers.org> - http://m.mongers.org/
  • Wiggins at Apr 4, 2003 at 2:14 pm
    ------------------------------------------------
    On Thu, 3 Apr 2003 14:05:19 -0500, Steve.E.Pittman@Medstar.net wrote:


    All,

    I added the "use strict;" statement to my script for the first time and
    received the following compilation errors:
    Global symbol "$LoginName" requires explicit package name at todaysFiles.pl
    line 43.
    Global symbol "$TMPNow" requires explicit package name at todaysFiles.pl
    line 45.
    Global symbol "@filenames" requires explicit package name at todaysFiles.pl
    line 48.
    Global symbol "$filenames" requires explicit package name at todaysFiles.pl
    line 49.

    This program works fine without the "use strict" statement?.please advise!!
    You have some obligatory reading to do :-)... You should read:

    http://perl.plover.com/FAQs/Namespaces.html
    perldoc strict
    perldoc -f my
    perldoc -f our

    Essentially you need to declare the namespace/scope of the variables you are using. Before they were automagically placed in the 'main::' namespace. This seems overly tedious at first, once you learn the practice you will forever appreciate it.
    Also, can someone offer an explanation of how "=" differs from "= ="??
    '=' is for assignment, '==' is for comparison...

    so you 'assign' a variable with the first:

    my $variable = 'value';

    you compare number values with the second:

    if ($variable == 4) {
    }

    http://danconia.org
  • R. Joseph Newton at Apr 4, 2003 at 3:29 pm

    Steve.E.Pittman@Medstar.net wrote:

    All,

    I added the "use strict;" statement to my script for the first time and
    received the following compilation errors:
    Global symbol "$LoginName" requires explicit package name at todaysFiles.pl
    line 43.
    This error means that "$LoginName was declared without a statement indicating what package it is meant to be part of. It is not a hard question to answer. Simply make sure that before you use a variable in your code, you tell the interpreter that it is being introduced:
    my $login_name;
    or
    my $login_name = "pittmans";

    It can get a little more complicated. If you care about your data, you will probably want to declare your variables only within subs or other blocks, so that it is more difficult to accidentally corrupt their values.
    This program works fine without the "use strict" statement?.please advise!!
    use strict;
    and deal with the errors the interpreter issues. If it gives you an error message, that is because you are doing something that will make errors more likely. Choosing not to use strict is a directive to the compiler "give me enough rope to ang myself" The compiler will respect that directive.
    Also, can someone offer an explanation of how "=" differs from "= ="??
    = assignment
    == numeric comparison

    If you use the assignment operator in a context calling for numeric comparision, the operation will return true unless you are assigning 0, the empty string '', or undef to the variable. If you have warnings enabled, the interpreter will catch most such cases and warn you about them.

    Joseph

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedApr 3, '03 at 7:05p
activeApr 4, '03 at 3:29p
posts4
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase