The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-17-2008
gholdbhurg gholdbhurg is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 26
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0