Cool/useful short examples of Perl?

David Matthewman david at matthewman.org
Tue Jun 7 20:52:14 BST 2011


On 31 May 2011, at 15:02, David Cantrell wrote:

> On Mon, May 30, 2011 at 04:27:30PM +0100, Denny wrote:
>> On Mon, 2011-05-30 at 15:36 +0100, David Precious wrote:
>>> if (! Email::Valid->address($email_address) ) {
>> Something wrong with 'unless'?
> 
> Yes.  Most of the time you'll either have an 'else' or want to add it
> later, and unless ... else is Just Wrong.

Well, in that case, it should be:

  if (Email::Valid->address($email_address) ) {
    # Code for if the e-mail address is valid.
    ...
  }
  else {
    # Code you were going to write in the block above.
    ....
  }

Otherwise your 'else' block is basically a double negative, and (IMAO) just as confusing for an 'else' block for an 'unless'.

OK, I admit, I've found myself wanting to add an 'else' block to an 'unless' statement. And it's awkward, but only for the short period of time it takes for me to rewrite it as an 'if' with the original code in the new 'else' block.

-- 
David Matthewman




More information about the london.pm mailing list