Skip to content

Instantly share code, notes, and snippets.

@dmitrybitman
Created May 24, 2011 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitrybitman/988580 to your computer and use it in GitHub Desktop.
Save dmitrybitman/988580 to your computer and use it in GitHub Desktop.
stat
#!/usr/bin/perl -w
use strict;
my $splitre = qr/\sU:(\S+).*?\sLT:(\d+)/;
my %re = (
'vk' => '^http://([^/]+.)?(vkontakte\.ru|vk\.com)[/$]',
'odkl' => '^http://([^/]+.)?(odnoklassniki\.ru|odkl.ru)[/$]',
'my' => '^http://([^/]+.)?(my.mail.ru|mir.mail.ru)[/$]'
);
my %sites = map { $_ => qr{$re{$_}} } keys(%re);
while (<>) {
my @line = m/$splitre/g;
next if @line == 0;
for (my $i=0; $i<@line; $i=$i+2) {
my $url = $line[$i];
my $count = $line[$i+1];
foreach my $group (keys %sites) {
if ($url =~ m{$sites{$group}}) {
print "$group $count\t1\n";
}
}
}
}
#!/usr/bin/perl -w
use strict;
my $group = '';
my $count = 0;
sub printResult
{
print "$group\t$count\n";
}
while (<>) {
my @line = split '\t';
if ($group ne $line[0]) {
if ($group ne '') {
printResult;
}
$group = $line[0];
$count = 0;
}
$count = $count + $line[1];
}
printResult;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment