use strict;
my $input;
my $title = '::';
while (1) {
print q(Parse? );
chomp($input = <STDIN>);
exit 1 if $input =~ /n(?=o)?/i;
do_map(do_parse(do_start())) if $input =~ /y(?=es)?/i;
print qq(Yes or no, dumbass.\n);
}
sub do_start {
print qq(File: );
while ($input = <STDIN>) {
chomp;
-r $input and last;
print qq(That isn't a file.\nFile: );
}
return 1;
}
sub do_parse {
die unless shift; # should never die here <.<
open(FILE,qq(<$input)) or die; # same as above
my (@raw,%hash,$last);
push(@raw,chomp($_)) while <FILE>;
close(FILE) or die; # may die here, whatever
foreach my $var (@raw) {
if ($var =~ /^$title/i) {
$var =~ s/^$title(.*)/$1/i;
$last = $var;
$hash{$last} = [];
next;
}
push(@{$hash{$last}},$var);
}
return \%hash;
}
sub do_map {
my $hash = shift;
map {
print qq(\u$_ tables:\n);
foreach my $dl (@{$hash->{$_}}) {
print q( ) x length $_, q( );
print $dl;
}
} keys %$hash;
}