As you may or may not know, perl will return the last value in a subroutine it sees... so
will return foo even without an explicit return 'foo';sub foo { 'foo'; }
foo will be printed, since it is the last real value perl saw in the subroutine, everything else was basically blank lines... BUT! one must be careful in this situation because if you ever come back and put code in after the if statement likeprint(foo(),"\n"); sub foo { if(1) { 'foo'; } else { 'bar'; } }
then you will get 1, the return value of a successful print. most people use an explicit return unless the value they are returning is the last line of the sub, since it is then much harder to miss.print(foo(),"\n"); sub foo { if(1) { 'foo'; } else { 'bar'; } print STDERR 'fooed'; }
- Ant
- Some of my best work - Fish Dinner
In reply to Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If?
by suaveant
in thread Can this If/Else be condensed into a 1 liner with a trailing If?
by jerrygarciuh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |