You could do:

map {
        push(@{$group{(split(/_/))[0]}}, $_);
} split(/,/);

but map { } in void context is, hmm... or at least along those lines.  I
haven't tested that.

Cheers,

-Andrew


On Sat, 1 Feb 2003, Perl wrote:

> I have a simple question for the group.  Consider the following string.
>
> $_ = 'use_name,mat_id,use_id,use_fname,mat_name,use_lname';
>
>
> How could I elegantly split/loop this into the following structure?
> %hash = (
>       use => ["use_name","use_id","use_fname","use_lname"],
>       mat => ["mat_id","mat_name"]
> };
>
> I started something like
>
> foreach (split(/,/)) {
>       /(\w+)_\w+/;
>       $group{$1}++;
> }
>
> But I need to push the values into an array with out doing tons of loops?
>
> Thanks,
> Jay
> _______________________________________________
> Boston-pm mailing list
> [EMAIL PROTECTED]
> http://mail.pm.org/mailman/listinfo/boston-pm
>
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to