EmmittSmith has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; open(TEST, 'test.txt') || die "Couldn't open it"; print "\nFile Opened\n\n"; my $i=1; my %list; while(<TEST>){ chomp($_); $_ = /(\w*)\s?(\w*)\n?/; print "$i : $2\,$1\n"; %list = ("$i" => ["$1","$2"]); $i+=1; } foreach $a(sort(keys(%list))){print "$list{$a}[1]\,$list{$a}[0]\n"} close(TEST); die "\n\nFile Closed\n";
test.txt: Emmitt Smith Walter Payton Barry Sanders Jim Brown
Thanks,
Emmitt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Associative Array Trouble
by Zaxo (Archbishop) on May 22, 2002 at 23:43 UTC | |
by EmmittSmith (Acolyte) on May 23, 2002 at 00:05 UTC | |
by tadman (Prior) on May 23, 2002 at 02:18 UTC | |
|
Re: Associative Array Trouble
by mt2k (Hermit) on May 23, 2002 at 05:15 UTC | |
|
Re: Associative Array Trouble
by rbc (Curate) on May 22, 2002 at 23:43 UTC | |
by merlyn (Sage) on May 23, 2002 at 00:18 UTC | |
by rbc (Curate) on May 23, 2002 at 16:46 UTC |