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

single quote in package variable names

by caelifer (Scribe)
on Nov 14, 2006 at 17:59 UTC ( #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


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


    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://584014]
Approved by bart
Front-paged by andyford
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2018-06-21 16:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.