<$fh>; # Drop column names on the floor
Somehow, it hurts me to see this in void context :-)
#!/usr/bin/perl
use strict;
use warnings;
use Text::ParseWords;
# WARNING: this code may generate some warnings
# but checking is omitted intentionally
my @headers;
{
local $_ = <DATA>;
chomp;
@headers = parse_line(',', 0, $_);
}
my @people;
while (<DATA>) {
chomp;
my @fields = parse_line(',', 0, $_);
push @people, { map { $headers[$_], $fields[$_] } 0 .. $#headers }
+;
}
printf qq(%s says "%s"\n), @{$people[0]}{@headers};
# Isha says "Hello!!"
__DATA__
Name,Comment
"Isha","""Hello!!"""
"Malav" ,"""koni comments nakhu ? tari?"""
"Mihir","""Dont know what to write :)"""
"Mukesh","""Kya comment add karun"""
"Tanmay Anjaria","""I - Intelligent S - Smart H - Highly thoughtful A
+- Antonyms should be taken for all of the above to know Isha :-)) Jus
+t Kidding... Keep Smiling, dear\u2026"""
Or, following original requirement exactly:
my %people;
while (<DATA>) {
chomp;
my @fields = parse_line(',', 0, $_);
for (0 .. $#headers) {
push @{$people{$headers[$_]}}, $fields[$_];
}
}
printf qq(%s says "%s"\n), map { $people{$_}[0] } @headers;
# Isha says "Hello!!"
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|