![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl sort | summer_cherry | Shell Programming and Scripting | 1 | 07-10-2008 05:09 AM |
| Sort and Unique in Perl | deepakwins | Shell Programming and Scripting | 20 | 02-11-2008 09:25 PM |
| sort function in perl | DILEEP410 | Shell Programming and Scripting | 2 | 09-14-2007 09:03 AM |
| sort and uniq in perl | reggiej | Shell Programming and Scripting | 4 | 05-18-2006 11:46 PM |
| Sort file in perl | annececile | Shell Programming and Scripting | 4 | 06-21-2002 09:52 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
how to do sort in perl?
Hi,
Can anyone advise how to correct my script pls? I'm not getting the correct output =( Details below: Logfile ======== Player Num : 14 Player Name : Jacee Thirkins MVP winner : 1998 End of details.... Player Num : 35 Player Name : Lander Diaz MVP winner : 2002 End of details.... Player Num : 14 Player Name : Jacee Thirkins MVP winner : 1999 End of details.... Player Num : 35 Player Name : Lander Diaz MVP winner : 2001 End of details.... Player Num : 14 Player Name : Oman Rodriguez MVP winner : 1997 End of details.... Player Num : 35 Player Name : Larry Simpkins MVP winner : 2003 End of details.... Player Num : 14 Player Name : Jacee Thirkins MVP winner : 1996 End of details.... Player Num : 35 Player Name : Lander Diaz MVP winner : 2002 End of details.... Player Num : 14 Player Name : Stephen Jabinzki MVP winner : 1999 End of details.... Player Num : 35 Player Name : Lander Diaz MVP winner : 2004 End of details.... Player Num : 35 Player Name : Larry Simpkins MVP winner : 2005 End of details.... Script ======= open (INFILE,"$inputfile"); open (OUTPUT, ">$outfile"); my %player_count; my @all_player; while ($cur_rec = <INFILE>) { if ( $cur_rec =~ m/Player Name/ ) { @record = split(/:/, $cur_rec); $playername = "$record[1]" . "$record[2]"; push(@all_player, $playername); } } @sorted_player = sort @all_player; for $player (@sorted_player) { if ("$player" eq "$prev_player" || $ctr == 0 ) { $ctr++; } else { $player_count{$ctr} = $player; $ctr=1; } $prev_player = $player; } $countr = 0; for $count (keys %player_count) { if ( $countr <= 4 ) { print "\nPlayer: $player_count{$count} MVP awards: $count\n"; $countr++; } else { $player_count{$player} = $ctr; $ctr = 0; } } close (TEST); close (OUTPUT); Expected output (should be in order who got the most awards in total): Top5 MVP winners =============== Lander Diaz Jacee Thirkins Larry Simpkins Oman Rodriguez Stephen Jabinzki |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|