Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL wantarray Function



Syntax

wantarray


Definition and Usage

Returns true if the context of the currently executing function is looking for a list value. Returns false in a scalar context.

Return Value

  • undef if no context

  • 0 if lvalue expects a scalar

Example

#!/usr/bin/perl -w

sub foo {
    return(wantarray() ? qw(A, B, C) : '1');
}

$result = foo();    # scalar context
@result = foo();    # array context

print("foo() in a  scalar context: $result\n");
print("foo() in an array  context:
@result\n");

It will produce following results:

foo() in a  scalar context: 1
foo() in an array  context:
A, B, C


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names