Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a double underscore in Perl?

Tags:

syntax

perl

I'm trying to understand someone else's Perl code without knowing much Perl myself. I would appreciate your help.

I've encountered a Perl function along these lines:

MyFunction($arg1,$arg2__size,$arg3)

Is there a meaning to the double-underscore syntax in $arg2, or is it just part of the name of the second argument?

like image 984
user10261 Avatar asked Sep 19 '08 15:09

user10261


3 Answers

There is no specific meaning to the use of a __ inside of a perl variable name. It's likely programmer preference, especially in the case that you've cited in your question. You can see more information about perl variable naming here.

like image 168
Mark Avatar answered Sep 27 '22 22:09

Mark


As in most languages underscore is just part of an identifier; no special meaning.

But are you sure it's Perl? There aren't any sigils on the variables. Can you post more context?

like image 41
hexten Avatar answered Sep 27 '22 23:09

hexten


As far as the interpreter is concerned, an underscore is just another character allowed in identifiers. It can be used as an alternative to concatenation or camel case to form multi-word identifiers.

A leading underscore is often used to mean an identifier is for local use only, e.g. for non-exported parts of a module. It's merely a convention; the interpreter doesn't care.

like image 22
JB. Avatar answered Sep 28 '22 00:09

JB.