chinamox has asked for the wisdom of the Perl Monks concerning the following question:
I have a tab delimited that looks somthing like this:
ect...Name City Languages Hong Xiao Chongqing English,Mandarin Rob Huston, TX English,German,Japanese Jess Springfield, IL English,French Mike Austin, TX English,Perl,Java
I have written this very cute little program to let you find out who knows which language.
#!/opt/bin/perl -w use strict; # don't allow unsafe constructs my ( $name, $city, $language, $search ); my $whole; my $count = 1; my $line; my @matched; print "What language would you like to search for? "; $search = <STDIN>; chomp $search; #open the employees file open (EMPLOYEES, "employees.txt"); #for each line while ($line = <EMPLOYEES>) { #remove the carriage return chomp $line; #splits the line between tabs and get the different elements ($name, $city, $language) = split /\t/, $line; next unless $language =~ /^$search/; print "$name speaks $search\n"; } close (EMPLOYEES);
The only problme is that right now it only works for the entry "English" because the other languages are buried English without spaces (only commas). What is the fastest way to parse the elements assigned to the $language $scaler?
Thanks for your time and any help offered.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A small comma parsing problem...
by davorg (Chancellor) on Oct 03, 2006 at 15:20 UTC | |
by chinamox (Scribe) on Oct 03, 2006 at 16:53 UTC | |
|
Re: A small comma parsing problem...
by hgolden (Pilgrim) on Oct 03, 2006 at 15:23 UTC | |
by chinamox (Scribe) on Oct 03, 2006 at 16:19 UTC | |
|
Re: A small comma parsing problem...
by ikegami (Patriarch) on Oct 03, 2006 at 15:20 UTC | |
|
Re: A small comma parsing problem...
by jdporter (Paladin) on Oct 03, 2006 at 15:37 UTC | |
by chinamox (Scribe) on Oct 03, 2006 at 16:16 UTC | |
|
Re: A small comma parsing problem...
by Jasper (Chaplain) on Oct 03, 2006 at 16:04 UTC | |
by chinamox (Scribe) on Oct 03, 2006 at 16:14 UTC |