Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: $_ haters anonymou

by Dominus (Parson)
on Dec 14, 2000 at 09:19 UTC ( #46572=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: $_ haters anonymou
in thread $_ haters anonymou

Says tilly:

> There is a small list of "special" symbols which are
> always in package main by default no matter what package you are in.
> *_ is one.

I thought that might be a useful thing to have, so I put a patch into 5.6.0 to add lots of those variables. So now if you want to have a variable that is always in package main for some reason, you can call it ${^_Ben_Tillys_Variable}, and no matter what package you are in, you always get the same thing.

It's documented at the very end of perlvar, as is the stuff Ben was discussing.


Comment on Re: $_ haters anonymou
Re: Re: $_ haters anonymou
by redcloud (Parson) on Dec 14, 2000 at 20:22 UTC
    Sayeth the Dominus:

    > So now if you want to have a variable that is always in package main for some reason, you can call it
    > ${^_Ben_Tillys_Variable}, and no matter what package you are in, you always get the same
    > thing.

    Forgive my ignorance -- and maybe it's just too early for me to be posting -- but I have to ask because it's confusing me: Why is this so much better than $main::Ben_Tillys_Variable? If it's just syntactic sugar, that's fine -- I just want to make sure I'm not missing something here....

    (BTW, Brother Dominus, good to have you back. I noticed an absence of posts from you for a few days.)

      Says redcloud:
      > Why is [${^_Ben_Tillys_Variable}] so much
      > better than $main::Ben_Tillys_Variable?
      That's a good question. It isn't that much better, but that wasn't the main point of the patch. The reason for the patch was that there are all these $^T, $^L, $^V, $^S variables already. They're all forced into package main::, which is what you want, because you don't want to have to say $main::^M everywhere. And we were starting to run out of letters! So I put the patch in so that the next time someone wants to make up a new feature and use a new $^M variable, they can call it ${^Emergency_Memory} instead. It will be forced into package main:: just like $^M is.

      Since I was doing that anyway, I thought I might as well reserve some of those variables for the user, just in case they turned out to be useful for someone. If not, it's OK, because it didn't cost anything.

        you don't want to have to say $main::^M everywhere.

        i blinked b4 replying, but you don't have to:

        $::^M is equivalent to $main::^M - 'main' is the default namespace.

        Or have I grabbed the wrong end of a pointy stick?

        cLive ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-10-25 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls