This isn't really what I would call elegant, but it does what you want in
one line of code:

# '_' is a \w, so avoid greediness by specifying a-Z, 0-9
$_ =~ s/(([a-zA-Z0-9]+)_\w+)/push @{$group{"$2"}}, "$1"; $1/ge;

For some reason you end up with an extra empty array entry (I'm not sure
why).
Here's my test code:

$_='use_name,mat_id,use_id,use_fname,mat_name,use_lname';
$_ =~ s/(([a-zA-Z0-9]+)_\w+)/push @{$group{"$2"}}, "$1"; $1/ge;
print "$_\n";
for( keys %group ) {
    print "$_ = [", join "]\, [", @{$group{ $_ }}, "]\n";
}

Grant M.



_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to