Lunchtime homework is always fun when you are learning
all of this stuff (like I am), and dvergin has already
done all of the hard work / taken us 90%
of the way there. So here is a pass at with most of what he did then just
played with the grep statement to get it to work as
discussed in the thread:
#!/usr/bin/perl -w
use strict;
open(DATA,"D:/JUNK/commafile.csv");
my @friends;
my @raw_list = <DATA>;
chomp @raw_list;
for (@raw_list) {
my @bits = split(/,/, $_);
my $sucker= {FIRSTNAME => $bits[0],
LASTNAME => $bits[1],
HAIRCOLOR => $bits[2]};
push @friends, $sucker;
}
my @real_friends = grep
{ lc(substr($_->{FIRSTNAME},0,1)) eq "j"
&& $_->{HAIRCOLOR} eq "brown" }
@friends;
foreach (@real_friends) {
print "Only real friends have \'$_->{HAIRCOLOR}\' hair ";
print " and names which begin with 'j' like my friend ";
print "\'$_->{FIRSTNAME} $_->{LASTNAME}\'\n";
if (($_->{FIRSTNAME} eq "John") &&
($_->{LASTNAME} eq "Kennedy")) {
print " Hey 'nandaya' you Novice level chump, ";
print "I know John Kennedy, \n";
print " I worked with John Kennedy, and 'nandeya', ";
print "you're no friend of John Kennedy.\n";
}
}
__DATA__
John,Brown,red
Fred,Flintstone,black
Jane,Brown,blond
Betty, Rubble,black
John,Kennedy,brown
Jodi,Brown,brown
Bill,Black,blond
June,Green,brown
John,McEnroe,brown
Erin,White,brown
nandeya
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.