Re: Use strict (beginner question)
On 2003-04-03 14:05:19 -0500, [EMAIL PROTECTED] 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 [EMAIL PROTECTED] - http://m.mongers.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Use strict (beginner question)
On Thu, 3 Apr 2003 14:05:19 -0500, [EMAIL PROTECTED] 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Use strict (beginner question)
[EMAIL PROTECTED] 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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]