Skip to content

Instantly share code, notes, and snippets.

@pwr22
pwr22 / counter.pl
Last active August 29, 2015 14:10
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}++
}
@pwr22
pwr22 / main.c
Created December 12, 2014 09:10
hash_get
static int (**hget(int (**t)[2], int k))[2] {
int (**t2)[2] = t;
for (int h = k & (SIZE - 1); **t2 && ***t2 != k; h = (h + 1) & (SIZE - 1), t2 = t + h);
return t2;
}
@pwr22
pwr22 / main.pl
Created January 18, 2015 22:19
Hash of Arrays of Hashes in Perl
# This is a hash
my %hashOfArraysOfHashs = ( key1 => [ { innerKey1 => 'is me', innerKey2 => 'is me' },
{ innerKey1 => 'is me', innerKey2 => 'is me' }],
key2 => [ { innerKey1 => 'is me', innerKey2 => 'is me' },
{ innerKey1 => 'is me', innerKey2 => 'is me' },
{ innerKey1 => 'is me', innerKey2 => 'is me' }]);
# This is a hashref
my $hashOfArraysOfHashs = { key1 => [ { innerKey1 => 'is me', innerKey2 => 'is me' },
{ innerKey1 => 'is me', innerKey2 => 'is me' }],
key2 => [ { innerKey1 => 'is me', innerKey2 => 'is me' },
@pwr22
pwr22 / main.pl
Last active August 29, 2015 14:13
TOD Greeter
#!/usr/bin/env perl
use Modern::Perl '2014';
my $hour = (localtime)[2];
my $TOD = do { if($hour < 12) { "morning"}
elsif($hour < 17) { "afternoon"}
else { "evening"}};
say $TOD