in reply to Re: Can't understand function returning undefs
in thread Can't understand function returning undefs
But if we are at it. My problem is that I have a function that returns two values when data is available to it and when no data remained it returns undef.
What I would like to do is to call this function in a while until all data is consumed. I tried to do this first bysub recv_data{ if(read_some_data){ return($stuff1, $stuff2); } else { return; } }
which failed due to the above reasons (i.e., the while block always executed since ($x, $y) = recv_data always evaluates to true even if the function returns undef).while(($x, $y) = recv_data){ ... }
I still have the option to write
but I fail to see this as elegant.while(1){ my($x, $y) = recv_data; last unless defined $x; ... }
How to organize this code so that I obtain the required behavior in an elegant and readable way?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Can't understand function returning undefs
by AnomalousMonk (Archbishop) on Sep 24, 2010 at 21:24 UTC | |
by rg0now (Chaplain) on Sep 24, 2010 at 21:32 UTC | |
Re^3: Can't understand function returning undefs (explicit)
by tye (Sage) on Sep 24, 2010 at 21:01 UTC | |
Re^3: Can't understand function returning undefs
by ikegami (Patriarch) on Sep 24, 2010 at 21:55 UTC |