laziness, impatience, and hubris | |
PerlMonks |
Return array from sub or return empty arrayby gregzartman (Initiate) |
on Jul 04, 2016 at 04:39 UTC ( [id://1167104]=perlquestion: print w/replies, xml ) | Need Help?? |
gregzartman has asked for the wisdom of the Perl Monks concerning the following question: I am doing some dev for a linux distro with a perl API for managing the configuration for the server. Quite a bit of the underling API are bits of perl code we call event and actions. One of the "practices" many follow is assigning an empty value when a string is set so as not to end up with a undef value. Something like this:
This is assuming some_method returns a scalar. I've just always used this approach but found that this doesn't work when returning arrays "some_method" I'm hoping you all can help me understand what perl is doing when it returns and array. Here's the bit of code I was testing with:
I was thinking that @array1 gets assigned @array2 via the get_array2 function unless undef, in which case @array1 get assigned the empty array (). However, I can see from this test code that my thinking is wrong. Thanks!
Back to
Seekers of Perl Wisdom
|
|