http://qs1969.pair.com?node_id=542227

jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I've run into this strange behaviour when playing with trying to make functions return different values from the number of parameters they were called with. If you test @_, and that you return from a do { ... } block where a variable is localized, the return value is undef if you don't add an else statement.

#!/usr/bin/perl -w use strict; sub foo { if (@_) { return do { my $dummy; 1; }; } else { return 0; } } # let's just remove the else sub bar { if (@_) { return do { my $dummy; 1; }; } return 0; } print foo().' '.foo('baz')."\n"; # that was expected print bar().' '.bar('baz')."\n"; # undef
################################################## Expected output: 0 1 0 1 ################################################## Actual output: 0 1 Use of uninitialized value in concatenation (.) or string at ./undef.p +l line 24. 0 ##################################################
"Keep pouring your ideas"

2006-10-07 Unapproved by planetscape once evidence of habitual plagiarism uncovered.