Perl: What is C <our>?

I am involved in learning my Perl. I am using the EPIC debugger in Eclipse. Whenever I have var used only once in sub, I get this warning:
Typographical errors are often displayed as unique variable names. If you have a good reason to have a unique name, then just point it out again to suppress the message somehow. C<our> declaration for this purpose.
What is a C<our> ? The standard search was unconvincing.

+6
source share
3 answers
  • As for the part of C<> that might confuse you, it seems that EPIC took the text in POD format and printed it raw instead of rendering it from POD to formatted text.

    C<our> in the POD syntax means "Print text" our "formatted as code", usually this means a font with a monolayer. This is like the StackOverflow `our` countdown environment format command your own question.

  • The error itself comes from the Perl diagnostics module, which provides extended explanations for other Perl cryptographic warnings (in this case, "Name"% s ::% s "is used only once: a possible typo"). In fact, judging by the formatting of the POD that confused you, the EPIC probably uses the POD source from which the above perldiag document was created .

  • If you ask what our does, you should read perldoc -f our - this is a way to create an alias in a global variable that is valid in a given scope (see tchrist asnwer for details).

  • Regarding the search method in this case, when you are looking specifically for what you expect from Perl keywords, it always pays Google for "perldoc someKeyword".

+11
source

our is a lexical domain alias for a global variable.

+5
source

This is a Perl::Critic post in which you can use our $var; to define a variable :-) for the described reason.

+2
source

All Articles