Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Checking Wrong Condition

by Divakar (Sexton)
on Apr 25, 2012 at 17:30 UTC ( #967120=note: print w/ replies, xml ) Need Help??


in reply to Re: Checking Wrong Condition
in thread Checking Wrong Condition

thanks for the response.

yes. i am using the if condition in my subroutine. can you please explain more about wantarray. i read in perldoc. but couldnt understand much as how it will work here..


Comment on Re^2: Checking Wrong Condition
Re^3: Checking Wrong Condition
by 2teez (Priest) on Apr 26, 2012 at 00:23 UTC

    Subroutine can return both scalar and list context values, so return a list context values as in our case here. One can use wantarray() to tell which context as stated in the perldoc -f wantarray documentation, and I quote "Returns true if the context of the currently executing subroutine or "eval" is looking for a list value. Returns false if the context is looking for a scalar. Returns the undefined value if the context is looking for no value (void context)."

    E.g:

    my @values=get_values(); # subroutine called print @values; ## print 12345 not 1,2,3,4,5 sub get_values{ my @init_val=grep $_=>1..5; if(wantarray){ # test list context return @init_val; }else{return join",",split} }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-07-11 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (217 votes), past polls