[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl bug or do I need to RTFM?



>From the original by Stewart Leicester, addenda by PwrSurge (Tim)
> 
> I copy/pasted the script into MacPERL, added a semi-colon (you should know
> where by now)...
> 
> On "Syntax Check..." - I got this error...
> 
> # Global symbol "x" requires explicit package name.
> File 'Untitled'; Line 5
> # Global symbol "pathSep" requires explicit package name.
> File 'Untitled'; Line 8
> # Untitled had compilation errors.
> 
> Now I'm lost - thought I figured everything out.  :)  (AGAIN, I'm a
> intermediate, not a expert.)

Oooh, something I sorta understand :).

Try this:

 #!perl -w
 use strict;
 my($x) = 1;


It's all in the scope :). strict is very strict, and it tries to prevent
you from stepping on your own toes. my() creates a variable with local
scope, so it doesn't collide with others.

An alternate:

 #!perl -w
 use strict;
 $main::x = 1;

Now the scope of $x is bound to the "main" package, the implicit
package  for globals and such.

Hope that is mostly correct. We learn best by teaching.

Geoff

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch