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

Don't you love how lisp made it's way into perl?

Now if only there were also the beauties of cond...

Replies are listed 'Best First'.
Re: Re: Re: creating a particular hash
by princepawn (Parson) on Jun 01, 2001 at 03:44 UTC
    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.

      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 :-)