This looks to me like a good opportunity to use a hash slice.
use strict; use warnings; my %user_info; my @fields = qw(name email foo bar); while (<DATA>) { chomp; my ($user, $attribs) = split /\s+/, $_, 2; my %record; @record{@fields} = split /\|/, $attribs; $user_info{$user} = \%record; } foreach my $user (keys %user_info) { print "Username:$user Real Name:$user_info{$user}{name}\n"; }
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re^2: regex to split a line
by davorg
in thread regex to split a line
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |