in reply to Re: Comparing an array with a regex array of strings?
in thread Comparing an array with a regex array of strings?
There's no need to strip off leading and trailing spaces if you split using a regex with optional whitespace around your delimiters. I get around the need for a %temp hash by using cascading maps.
use strict; use warnings; use Data::Dumper; open my $csvFH, q{<}, \ <<EOD or die $!; Person1, Name = Lydia, Age = 20, Gender = F Person2, Name = Carol, Age = 54, Profession = Student, Gender = F, Hei +ght = 4'8 Person3, Name = Andy, Age = 37, Location = USA, Gender = M, Weight = 1 +17 Person4, Name = Nick, Age = 28, Gender = M EOD my %people = map { $_->[ 0 ], { map { split m{\s*=\s*} } split m{\s*,\s*}, $_->[ 1 ] } } map { chomp; [ split m{\s*,\s*}, $_, 2 ] } <$csvFH>; print Data::Dumper->Dumpxs( [ \ %people ], [ qw{ *people } ] );
I hope this is of interest.
Cheers,
JohnGG
|
|---|