On Feb 14, Robin Sheat said:
>I have a set of functions that send an XML element, wait for a response,
>parse the response, and return it. However, there are often cases where
>the resulting XML is never used, and so parsing it is pointless. Is
>there a way that a sub can tell where the result is going to go, so that
>it can not do the parsing if the result is going to be immediatly
>discarded?
Yes, use wantarray().
sub foo {
if (not defined wantarray) { print "void context\n" }
elsif (wantarray) { print "list context\n" }
else { print "scalar context\n" }
}
foo();
$x = foo();
@y = foo();
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>