Skip to content

Instantly share code, notes, and snippets.

@thecoshman
Created February 8, 2017 20:33
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 thecoshman/b89718c8ef4f6164015aaab9614ab6ef to your computer and use it in GitHub Desktop.
Save thecoshman/b89718c8ef4f6164015aaab9614ab6ef to your computer and use it in GitHub Desktop.
A program I wrote in may 2013... I've no idea what I wanted it to do...
#!/usr/bin/perl
use warnings;
use strict;
sub load_file_data{
my $folder = 'unzipped';
opendir FOLDER, $folder;
my @files;
while (readdir FOLDER){
next if /^\.\.?$/;
push @files, $folder . "/" . $_;
}
@files = map{ $_->[0] } sort { $a->[1] <=> $b->[1]} map { [$_, /\.(\d+)$/, $_]} @files;
return @files;
}
sub menu{
}
my $promt = ":";
my @files = load_file_data();
while(1)
{
print "$promt";
chomp (my $input = <>);
if($input eq "ls"){
local $, = "\n";
print @files;
my $count = scalar @files;
print "\n $count files\n";
next;
}
if($input =~ /^\/.*\//){
my ($pattern) = $input =~ /^\/(.*)\//;
print "applying regex... matching '$pattern'\n";
for my $file (@files){
my $matches_found = 0;;
print "=][= Checking $file =][=\n";
open my $file_handle, '<', $file or die "Can't open $file\n";
while(<$file_handle>){
chomp;
print "$_\n"if $_ =~ /$pattern/;
}
close $file_handle;
}
next;
}
if($input =~ /^keep \/.*\//){
my ($pattern) = $input =~ /^keep \/(.*)\//;
print "applying regex... matching '$pattern'\n";
my @updated_file_list;
FILE: for my $file (@files){
my $matches_found = 0;;
print "=][= Checking $file =][=\n";
open my $file_handle, '<', $file or die "Can't open $file\n";
while(<$file_handle>){
chomp;
push @updated_file_list, $file and next FILE if $_ =~ /$pattern/;
}
close $file_handle;
}
undef @files;
@files = @updated_file_list;
next;
}
if($input =~ /^remove \/.*\//){
my ($pattern) = $input =~ /^remove \/(.*)\//;
print "applying regex... matching '$pattern'\n";
my @updated_file_list;
FILE: for my $file (@files){
my $matches_found = 0;;
print "=][= Checking $file =][=\n";
open my $file_handle, '<', $file or die "Can't open $file\n";
while(<$file_handle>){
chomp;
next FILE if $_ =~ /$pattern/;
}
close $file_handle;
push @updated_file_list, $file
}
undef @files;
@files = @updated_file_list;
next;
}
if($input =~ /win/){
for my $file (@files){
my $matches_found = 0;;
print "=][= Checking $file =][=\n";
open my $file_handle, '<', $file or die "Can't open $file\n";
while(<$file_handle>){
print "$_\n"if $_ =~ /2012\.02\.22/;
}
close $file_handle;
}
next;
}
if($input eq "q"){
last;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment