sivasakthi wrote:
Hi all,
I have file like that following,
site_name access_time
www.google.com 14:13:04|14:13:04|
172.16.5.49 14:12:10|14:12:56|
172.16.65.53 14:12:41|14:12:58|
172.16.671.35 14:12:29|
from the above file i need to print the sites & no of accessed
connections with sort.
open(FILE,:/tmp/test.txt/" or die "cant open the file");
my @domain_info=<FILE>;
foreach my $site (@domain_info)
{
my ($domain,$data)=split(" ",$site);
$domain{$domain}.=$data;
}
foreach my $dname ( keys %domain)
{
my @conn=split('\|',$domain{$dname});
my $noofconn=$#conn+1;
$noofconns{$dname}+=$noofconn;
}
foreach $dname (sort {$noofconns{$b} <=> $noofconns{$a}} %noofconns)
{
print "$domain\n";
print "$noofconns\n";
}
close (<FILE>);
Could u help me to solve the pbm???
use strict;
use warnings;
my %noofconns;
open FILE, '/tmp/test.txt' or die "Can't open the file";
while (<FILE>) {
my ($domain, $data) = split;
my $count = $data =~ tr/|//;
next unless $count;
$noofconns{$domain} += $count;
}
close FILE;
foreach my $domain (sort {$noofconns{$b} <=> $noofconns{$a}} keys %noofconns) {
print "$domain\n";
print "$noofconns{$domain}\n";
}
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/