my (%hash); my $data = "$BaseDir/perf.log"; open STUFF, $data or die "cannot open for read $!"; while ( ) { chomp; #my $X = "html"; #next if ( $_ !~ /^$X/ ); # Only look at lines begin with the topic next if ( $_ !~ /^[a-z]/ ); # Only look at lines begin with the topic my ($topic, $desc, $url, $hits) = split "," ; if ($topic){ ${hash}{$url}{topic} = $topic if ($topic); ${hash}{$url}{desc} = $desc if ($desc); ${hash}{$url}{url} = $url if ($url); ${hash}{$url}{hits} = $hits if ($hits); } } close STUFF; print Dumper %hash , "\n"; print "Sort Numeric using <=> with supersort\n"; foreach my $sorted_url ( reverse sort { $hash{$a}->{'hits'} <=> $hash{$b}->{'hits'} } keys %hash){ print $sorted_url, " has got ", ${hash}{$sorted_url}{hits}, " hits \n"; #### # -|print_topic|--------------------------------------------------------------- # Pre : t_topic # Post: # ----------------------------------------------------------------------------- sub print_topic ($) { my $t_topic = shift; open( INFILE, "$conf_file" ) or die "$!"; while () { chomp; my (%hash); next if 0 == length($_); # Solves "Use of uninitialized value in .......... " next if ( $_ !~ /^$t_topic/ ); # Only look at lines begin with the t_topic my ($topic, $desc, $url, $hits) = split "," ; if ($topic) { ${hash}{$url}{topic} = $topic if ($topic); ${hash}{$url}{desc} = $desc if ($desc); ${hash}{$url}{url} = $url if ($url); ${hash}{$url}{hits} = $hits if ($hits); } #print "Sort Numeric using <=> with supersort\n"; #print Dumper %hash , "\n"; foreach my $sorted_url ( reverse sort { $hash{$a}->{'hits'} <=> $hash{$b}->{'hits'} } keys %hash){ print $sorted_url, " has got ", ${hash}{$sorted_url}{hits}, "\n"; } } close INFILE; }