Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl syntax question

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
Hi,

I inherited some perl codes from my ex-coworker.

One line of codes is like this:

Code:
return [COLOR=red]wantarray[/color] ? ($rc, $res) : $res;

What is the bare word 'wantarray'? Shouldn't be something like '$wantarray'? And I can not find anywhere the bareword 'wantarray' gets assigned a value.

This code is very old and has been used for many years. No one has ever asked, nor can they explain it to me. Is it safe to say this is simply a typo?

Thank you for you help.
 
wantarray returns true if the caller has invoked your code in a list context, and false if it's called in a scalar context.

In this example, he returns an array containing a return code and a value in a list context, and otherwise just the scalar value $res.

Does this help?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Larry Wall himself acknowledges that it's badly named and should probably have been called "wantlist".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top