Skip to content

Instantly share code, notes, and snippets.

Last active Jan 1, 2016
What would you like to do?
Perl script to go through the leaked Snapchat database of phone numbers and user names, and divide it into separate CSV files split by location. Will create a file for each location in a locations/ subdirectory in the current working directory. Will report the totals for each location in CSV format.
use strict;
print "Reading schat.csv\n";
unless ( open ( FILE, "<schat.csv") ) {
print "Cannot open file for read\n";
my @foo = <FILE>;
chomp( @foo );
close FILE;
print "Checking for locations directory\n";
mkdir "locations" unless -d "locations";
print "Processing...\n";
my %locations;
foreach my $foo ( @foo ) {
$foo =~ s/"$//;
$foo =~ s/^"//;
$foo =~ s/","/,/g;
my @bar = split ",", $foo;
if( exists $locations{$bar[2]} ) {
$locations{$bar[2]} += 1;
} else {
$locations{$bar[2]} = 1;
unless ( open ( FILE, ">>locations/$bar[2].csv") ) {
print "Cannot open $bar[2].csv for write";
print FILE "$foo\n";
my $total = 0;
foreach my $key (sort keys %locations) {
print "$key,$locations{$key}\n";
$total = $total + $locations{$key};
print "Total = $total\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment