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?
In reply to Re^2: Can't understand function returning undefs
by rg0now
in thread Can't understand function returning undefs
by rg0now
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |