Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Perl oddities

by Anonymous Monk
on Mar 01, 2005 at 21:28 UTC ( [id://435621]=note: print w/replies, xml ) Need Help??


in reply to Perl oddities

$::foo refers to the global variable called foo in the main package, not in the current package.

This works out the same for package main, but it just doesn't DWIM for other packages. The first three times I read through the documentation, I assumed it was just refering to this similarity: clearly, the writers of the Perl parser could tell what package they were in, so they could expand $::foo appropriately. After all, they need to figure out packages for function calls. Instead, it means the same as $main::foo, something that a simple regexp could do for me, if I wanted it to.

Since I thought the point of the package notation was to let the globals stand out with the double colon sigil syntax, I was disappointed to learn that I'd have to hard-code the package name in multiple places: first, in the the package, and second, for all the global variables within that package.

"our" variables solve the hard-coded package name issue, but don't have a special sigil to make them stand out as globals anymore...*sigh*
--
Ytrew

Replies are listed 'Best First'.
Re^2: Perl oddities
by TimToady (Parson) on Mar 01, 2005 at 21:41 UTC
    In Perl 6, :: behaves more like you expect, and is no longer automatically associated with either package main or any other top-level package. Class names are searched for starting in the current package, so $::foo would be a variable in the current package if declared there.
Re^2: Perl oddities
by brian_d_foy (Abbot) on Mar 01, 2005 at 21:34 UTC

    I just made package variable names start with a capital letter. That way I could remind myself I might be ruining someone else's day by playing with it.

    --
    brian d foy <bdfoy@cpan.org>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://435621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found