Dear Monks! Please help this perl novice here.
I have a sample csv file in the following format
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
I need to parse the values of Name, Age and Gender of one particular person. (In reality, I have 20 such parameters to parse among other junk). These parameters are for each person are in no particular order. I am not sure how to compare @terms with @array to get values Carol, 54 and F. Any suggestions would really help me. Thank you fellow monks!
my @terms = qw(Name Age Gender);
my $match = "Person2"
while (<$file>) {
chomp;
if (/$match/){
@array= split(/,/);
#What next???
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.