Skip to content

Instantly share code, notes, and snippets.

@pwr22
Last active August 29, 2015 14:10
Show Gist options
  • Save pwr22/bf476da4d1fa0460d736 to your computer and use it in GitHub Desktop.
Save pwr22/bf476da4d1fa0460d736 to your computer and use it in GitHub Desktop.
Perl URL path counter
#!/usr/bin/env perl
use v5.10; use strict; use warnings;
my %counts;
for my $line (<>) {
my $path = (split /\?/, (split / /, $line)[2])[0];
$counts{$path}++
}
while (my ($path, $count) = each %counts) {
say "$count $path"
}
#!/usr/bin/env perl
use v5.10; use strict; use warnings;
my %counts;
for my $line (<>) {
# short circuit where possible
my $path = (split /\?/, (split / /, $line, 4)[2], 2)[0];
$counts{$path}++
}
while (my ($path, $count) = each %counts) {
say "$count $path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment