Perl return undef

Question

In Perl what is the difference between return and return undef

perl return undef

Answer

Using “return” alone returns an empty list in list context and undef in scalar context. On the other hand “return undef” always returns undef even in list context. Generally speaking it is not a good idea to return undef from a subroutine normally used in list context:

Tags:

Add a Comment

Your email address will not be published. Required fields are marked *