[Chicago-talk] Limiting a hash, or producing an interesting list

Jay Strauss me at heyjay.com
Wed Nov 26 09:35:07 CST 2003


I think my way:

    my @heading = someFunc();
    my (%all,%offset);
    my @interesting = qw/symbol expiration strike/;
    @all{@heading} = (0..$#heading);
    @offset{@interesting} = delete @all{@interesting};

is better than your way:

 my @interesting = qw( what you knead );
 my @header = qw( what you get );
 my %fieldz = map { $header[$_] => $_ } ( 0..$#header );
 my @offsetz = grep { defined } @fieldz{@interesting};
 my %foo = ();
 @foo{@knead} = @input{@offsetz};

so there.

Ps, How did you arrive at the conclusion I'm thinking in variables?  Take a
look at my original post.  Its all about lists

Jay

----- Original Message -----
From: "Steven Lembark" <lembark at wrkhors.com>
To: "Chicago.pm chatter" <chicago-talk at mail.pm.org>
Sent: Tuesday, November 25, 2003 11:28 PM
Subject: Re: [Chicago-talk] Limiting a hash, or producing an interesting
list


>
>
> -- Jay Strauss <me at heyjay.com>
>
> > That's not really what I want though.
> >
> > your way, I end up with a hash with everything, and an array that tells
me
> > the offsets in my original array.
> >
> > But I want a hash with only the stuff I think is interesting
>
> ok, assign the slice to a hash instead of an array:
>
> my %foo = ();
>
> @foo{@knead} = @input{@offsetz};
>
> Learn to think in terms of lists rather than "variables",
> it's one of the more powerful attributes of Perl -- and
> perhaps the only reason LISP has survived this long.
>
>
>
> --
> Steven Lembark                               2930 W. Palmer
> Workhorse Computing                       Chicago, IL 60647
>                                             +1 888 359 3508
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
>




More information about the Chicago-talk mailing list