in reply to Question Marks in Subroutine Names

If it really bothers you that much, you could do...

use constant YES => 1; use constant NO => 0; # ... my $answer = is_contact_female ? YES : NO;

... but it's shamefully redundant if is_contact_female is already returning a true or false; not to mention limiting (ie, you couldn't use 1 to represent 'Yes, and adult', 2 to be 'Yes, but teen', etc.).

    --k.


Replies are listed 'Best First'.
(crazyinsomniac: bah) Re^2: Question Marks in Subroutine Names
by crazyinsomniac (Prior) on May 08, 2002 at 10:40 UTC
      ++crazyinsomniac ... I would probably go just one step further and use type-globbing to simplify the subsequent function call - For example ...

      *{'is_contact_female?'} = sub { my @args = @_; ... }; &{'is_contact_female?'}( @args );

      I first encountered this manner of subroutine assignment in Damian Conway's selfGOL obfuscation, a "must-read" for any aspiring obfuscator.

       

Re: Re: Question Marks in Subroutine Names
by dug (Chaplain) on May 08, 2002 at 02:55 UTC

    I'm thinking of this in a boolean context, so what you call limiting I wasn't thinking of as limiting in this context. Good point though. However, this is a hideously ugly solution that could easily be taken care of by allowing question marks in subroutine names.