Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Perl oddities

by Anonymous Monk
on Mar 01, 2005 at 21:28 UTC ( #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*

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 <>

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2019-11-21 23:59 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (107 votes). Check out past polls.