Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Re: $_ haters anonymou

by redcloud (Parson)
on Dec 14, 2000 at 20:22 UTC ( #46636=note: print w/ replies, xml ) Need Help??

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

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

Comment on Re: Re: $_ haters anonymou
Re: $_ haters anonymou
by Dominus (Parson) on Dec 14, 2000 at 22:27 UTC
    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.


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

        Says cLive ;-):
        Actually they're both syntax errors.

        If they weren't syntax errors, then yes, the variable $::^M is identical to $main::^M. But not because main is the default namespace. It's because the empty stash name is interpreted as though you had said main instead. See line 579 of gv.c:

        if (!*name) return gv ? gv : (GV*)*hv_fetch(PL_defstash, "main::", + 6, TRUE);
        If the name turns out to have been empty, Perl looks up the main stash instead.

        Mark Dominus
        Perl Paraphernalia

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-07-12 14:06 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (240 votes), past polls