Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: What exactly is C<our>?

Tags:

perl

I am in the process of teaching my self Perl. I am using the EPIC debugger in Eclipse. Whenever I have a var used only one time in a sub I get this warning:
Typographical errors often show up as unique variable names. If you had a good reason for having a unique name, then just mention it again somehow to suppress the message. The C<our> declaration is provided for this purpose.
What is C<our>? Standard searching was inconclusive.

like image 556
Cooter Avatar asked Jan 25 '11 18:01

Cooter


2 Answers

  • As far as C<> part that may have confused you, it looks like EPIC took a text in POD format and printed it raw instead of rendering it from POD into a formatted text.

    C<our> in POD syntax means "Print text 'our' formatted as code", usually meaning mono-spaced font. This is similar to StackOverflow's `our` backtick-surrounded format command your own question used.

  • The error itself comes from Perl's diagnostics module, which provides extended explanations for otherwise somewhat cryptic Perl warnings (in this case, "Name "%s::%s" used only once: possible typo"). As a matter of fact, judging from the POD formatting which confused you, EPIC probably uses the source POD from which the above-linked "perldiag" document was generated.

  • If you're asking what our does, you should read perldoc -f our - it is a way to create an alias into a global variable effective in a given scope (see tchrist's asnwer for details).

  • As far as googling technique in this case, when you're searching specifically for what you expect to be Perl keywords, it always pays to google for "perldoc someKeyword".

like image 161
DVK Avatar answered Oct 13 '22 01:10

DVK


our is a lexically scoped alias to a global variable.

like image 23
tchrist Avatar answered Oct 13 '22 02:10

tchrist