Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: creating a particular hash

by Henri Icarus (Beadle)
on Jun 01, 2001 at 03:32 UTC ( #84791=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://84791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2023-02-07 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (38 votes). Check out past polls.

    Notices?