I was reading through my old Beginning Perl book to get up to speed on Perl again, when I saw a joke the author had made that there was no elsunless in Perl. This got me wondering: could you use an else block with unless like you could with if, in case the unless failed. My hypothesis was that it wouldn't work, as it seemed....I don't know,counterintuitive. In retrospect, it was a pretty silly hypothesis, but it just didn't feel right that this could work at the time.
So i wrote a little block of code to test it:
#!perl use warnings; use strict; unless(1){ print "Hello\n"; } else{ print "WHAT?!!!\n"; }
...and, to my surprise, it spitted out : WHAT?!!!
This is probably not news to all you old hats at the monastery, but I never realised you could do it, and I wondered how many other new initiates didn't either. So I posted it here just in case.
In reply to unless....else by amrangaye
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |