Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

single quote in package variable names

by caelifer (Scribe)
on Nov 14, 2006 at 17:59 UTC ( [id://584014]=perlquestion: print w/replies, xml ) Need Help??

caelifer has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks:

I'm trying to find more information on the $pkg'var_name = 'foo'; construct. I understand that this is equivalent to $pkg::var_name = 'foo';, but where can I find more documentation for this syntax? Any pointers are welcome and appreciated.

- caelifer

UPDATE:

Thanks a lot for your answers. I was working through some old scripts and this construct came up. Believe it or not, but I could not remember where I did see the explanation and the google search did not turn anything useful. This really drove me nuts for a while so I had to ask... :) Once again perlmonks came through for me. Thank you.

Replies are listed 'Best First'.
Re: single quote in package variable names
by Ovid (Cardinal) on Nov 14, 2006 at 18:06 UTC

    From perlmod:

    The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house", you'll be accessing $owner::s; that is, the $s variable in package "owner", which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house".

    Cheers,
    Ovid

    New address of my CGI Course.

      And that's referenced right in the middle of the second paragraph of perldata:

      ... In some cases, it may be a chain of identifiers, separated by "::" (or by the slightly archaic "'"); all but the last are interpreted as names of packages, to locate the namespace in which to look up the final identifier (see "Packages" in perlmod for details).
Re: single quote in package variable names
by bart (Canon) on Nov 14, 2006 at 18:05 UTC
    It's the old, deprecated, perl4 syntax, borrowed stolen from Ada (as is the name package, BTW). So there. Preferably, don't use it, but it works.
Re: single quote in package variable names
by VSarkiss (Monsignor) on Nov 14, 2006 at 22:27 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://584014]
Approved by bart
Front-paged by andyford
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found