Question: In Haskell (F#, Ocaml, and others), I can do this:

```
sign x |  x >  0        =   1
       |  x == 0        =   0
       |  x <  0        =  -1

```

Which calculates the sign of a given integer.

This can concisely express certain logic flows; I've encountered one of these flows in Perl.

Right now what I am doing is 

```
sub frobnicator
{
   my $frob = shift;
   return "foo" if $frob eq "Foomaticator";
   return "bar" if $frob eq "Barmaticator";
   croak("Unable to frob legit value: $frob received");
}

```

Which feels inexpressive and ugly.

This code has to run on Perl 5.8.8, but of course I am interested in more modern techniques as well.

Answer: 
Here's one other possible approach, which is still a bit wordy, but perhaps reflects the flow better. (In the book Perl Best Practices, the author suggests mostly avoiding the postfix form of `if` because you need to scan all the way to the right to understand what is going on.) You could add parentheses if that helps to highlight the condition.

```
sub sign
{
    my $x = shift;
    $x  > 0  and return  1;
    $x == 0  and return  0;
    $x  < 0  and return -1;
}

sub frobnicator
{
    my $frob = shift;

    $frob eq "Foomaticator" and return "foo";
    $frob eq "Barmaticator" and return "bar";

    croak("Unable to frob legit value: $frob received");
}

```
For what it's worth, Perl 5.10 or later gives you:

[given](http://perldoc.perl.org/functions/given.html)

...which would allow:

```
...
use feature qw( switch say);
use Carp;
sub frobnicator {
    my $frob = shift;
    given ($frob) {
        when ('Foomaticator') {
            return q(foo);
        }
        when ('Barmaticator') {
            return q(bar);
        }
        default {
            croak(qq(Unable to frob legit value: $frob received));
        }
    }
}

```