views:

986

answers:

7

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?

+1  A: 

I'm fairly certain arg2__size is just the name of a variable.

Haabda
+10  A: 

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.

Mark
+11  A: 

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?

hexten
Jeez, they let anyone in here ;)
Ovid
Yeah – what is the site coming to. Seriously.
Aristotle Pagaltzis
I fixed up the sigils, so now you're answer makes no sense. :)
brian d foy
+2  A: 

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.

JB
+2  A: 

In the context of your question, the double underscore doesn't have any programmatic meaning. Double underscores does mean something special for a limited number of values in Perl, most notably __FILE__ & __LINE__. These are special literals that aren't prefixed with a sigil ($, % or @) and are only interpolated outside of quotes. They contain the full path & name of the currently executing file and the line that is being executed. See the section on 'Special Literals' in perldata or this post on Perl Monks

Drew Stephens
+1  A: 

Mark's answer is of course correct, it has no special meaning.

But I want to note that your example doesn't look like Perl at all. Perl variables aren't barewords. They have the sigils, as you will see from the links above. And Perl doesn't have "functions", it has subroutines.

So there may be some confusion about which language we're talking about.

AmbroseChapel
I edited the question to add sigils, so now this answer is a little out of date. Note, however, that those barewords could have been subroutine names. And, Perl does have functions. They're listed in perlfunc. :)
brian d foy
A: 

You will need to tell the interpreter that "$arg2" is the name of a variable. and not "$arg2__size". For this you will need to use the parenthesis. (This usage is similar to that seen in shell).

This should work MyFunction($arg1,${arg2}__size,$arg3)

--Binu