develooper Front page | perl.beginners | Postings from April 2012

Re: sort and count match in file

Thread Previous | Thread Next
From:
Shawn H Corey
Date:
April 15, 2012 10:58
Subject:
Re: sort and count match in file
Message ID:
4F8B0C49.5050804@gmail.com
On 12-04-15 01:44 PM, Вячеслав Агапов wrote:
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use diagnostics;
> use 5.010;
>
> use IO::Compress::Gzip;
> use IO::Uncompress::Gunzip;
>

my %count = ();

> my $file = "log.gz";
> my $ungzip = new IO::Uncompress::Gunzip($file);
> @arr = grep/work/,<$ungzip>;
>
> foreach my $text (@arr) {
>          @arr1 = split / /,$text;
>          @sort = ($arr1[3],$arr1[4]);
>          say "$sort[0] =>  $sort[1]";

   $count{$sort[0]}{$sort[1]} ++;

> }

for my $k1 ( keys %count ){
   for my $k2 ( keys %{ $count{$k1} }){
     print "$k1 - count of $k2($count{$k1}{$k2})\n";
   }
}


-- 
Just my 0.00000002 million dollars worth,
   Shawn

Programming is as much about organization and communication
as it is about coding.

[updated for today's programmers]
"Show me your code and conceal your interfaces, and I shall continue
to be mystified. Show me your interfaces, and I won't usually need
your code; it'll be obvious."
	-- Fred Brooks

Don't be clever; being great is good enough.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About