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

History of 'our'

by jeffa (Bishop)
on Jul 22, 2000 at 22:25 UTC ( [id://23911]=perlquestion: print w/replies, xml ) Need Help??

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

Buckaroo Buddha recently asked a question about strict in the node looking for Advice on how strict i should really be. In his code he used the keyword our, which is now deprecated. I looked through some reference manuals (not extensively, please forgive) and could not find any info on this keyword.

I tried a little code to see what Perl v5.005_03 had to say:

use strict; our $stuff = 5; print "$stuff\n";
and received the following:
Use of reserved word "our" is deprecated ... Global symbol "$stuff" requires explicit package name ...
The first line is just a warning, to be expected with the -w option, but the second line is the result of a syntax error, sort of goes against the definition of deprecated I would think. But this has to do with use strict, which doesn't appear to like 'our'.

Can any one tell a little history about the reserved word 'our' and maybe why it is deprecated? Is it similar to Java's protected modifier?

Much thanks :)

Replies are listed 'Best First'.
RE: History of 'our'
by autark (Friar) on Jul 22, 2000 at 22:47 UTC
    I don't know much about its history, but I know the 'our' keyword is something that had been planned for a long time. The deprecated warning was put in in perl5 (don't remember exactly when) because they knew that they eventually where going to support it.

    Thus if you say:

    perl -lwe 'sub our { print shift } $foo = "bar"; our $foo'
    you'll be warned by perl that your _use_ of the _reserved_ word 'our' is now deprecated (as in don't do that :-).

    The 'our' keyword has not had any function prior to perl5.6 (unless you count experimental versions that is).

    But why did they have to tell us not to use 'our' ? Well, take a look at that code again. In perl prior to 5.6 it prints "bar" (and may give you the warning) - in perl5.6 it doesn't print anything out because you now declare the $foo variable rather than sending it to a function called 'our'.

    Autark

RE: History of 'our'
by reptile (Monk) on Jul 22, 2000 at 22:51 UTC

    'our' has been reserved in versions earlier than 5.6.0. Saying it's deprecated is likely just bad wording. In 5.6.0, the 'our' keyword is synonymous with 'use vars' to declare package globals. This is AFAIK (one of the 5.005* perldelta pages, i believe, mentions that 'our' has been reserved).

    local $_ = "0A72656B636148206C72655020726568746F6E41207473754A"; while(s/..$//) { print chr(hex($&)) }

      In 5.6.0, the 'our' keyword is synonymous with 'use vars' to declare package globals.
      Uh, no. Not quite. It's use vars but with lexical scoping, so if it's inside a block, it loses effect after the block.

      -- Randal L. Schwartz, Perl hacker

      No, saying "use of reserved word XXX is deprecated" is a very proper message; you're using a bareword, and Perl is letting you know you shouldn't, since it's reserved for a future use. Perl didn't say "use of XXX is deprecated."

      $_="goto+F.print+chop;\n=yhpaj";F1:eval

        Okay, I consider myself a fairly advanced Perl programmer (after over a dozen years of it), but I find that distinction pretty danged subtle. I'd say the message "use of reserved word XXX is deprecated" is very poorly worded. It very much sounds like "use of XXX is deprecated, and, by the way, it is a reserved word".

        The existence of perldiag.pod helps relieve this problem (it says "Future versions of perl may use it as a keyword..." for this message).

        But it is still terrible because the meaning of "reserved word" in C (the only other place I've heard that term) is "a word reserved for use by the language", that is "if", "else", "goto", etc. So a "reserved word" in C is the same as a "keyword" in Perl.

        It is strange that Perl, a language that takes much from C, to use C's phrase for "keyword" as Perl's phrase for "not yet a keyword".

        In fact, I just did some checking of my facts, and I found the use of the term "reserved word" for what Perl calls "keyword" in several places other than C. In fact, Perl uses the term "reserved word" to include current keywords (see perldata.pod) so to say "'our' is a reserved word" doesn't even tell you that "our" isn't currently a keyword.

        A much better error message would be "The bareword XXX may become a Perl keyword, please quote it". *sigh*, now I have a moral obligation to submit a patch. :)

        OK. </rant>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found