in reply to creating a particular hash

Using tye's mapcar -- map for more than one list, you could:
my %hash = mapcar { @_ } map { [ split /,/ ] } split(":", $str);

Replies are listed 'Best First'.
Re: Re: creating a particular hash
by Henri Icarus (Beadle) on Jun 01, 2001 at 03:32 UTC
    Don't you love how lisp made it's way into perl?

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

      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.