in reply to Re: Re: creating a particular hash
in thread creating a particular hash

have you seen Switch?

Also, because I am converting a lot of lisp and scheme code, I dont really like cond very much.

In Perl, I can be much more concise:

return undef if !$bindings ; return (extend $bindings) if (var_match $pattern) ; return pat_match(rest $input) if @$input ;
The equivalent cond I do find a bit harder to follow.

Replies are listed 'Best First'.
(Ovid - chaining operators) Re(4): creating a particular hash
by Ovid (Cardinal) on Jun 01, 2001 at 19:26 UTC

    If you have a default value to return, this is where I prefer to chain the "x ? y : z" operator:

    return ! $bindings ? undef : var_match $pattern ? extend $bindings : @$input ? pat_match(rest $input) : $default_value;

    I know that it looks a little odd at first, but once you get used to the syntax, I find it even easier than case or switch statements.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Don't you get into trouble with operator precedence when you do this and start using && and such in your conditionals? Or am I just remembering old bugs in my C code :-)