-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow
executable file
·37 lines (30 loc) · 830 Bytes
/
show
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/perl
use strict;
use warnings;
use encoding 'utf-8';
use Parse;
use Data::Dumper;
for my $lawFile (glob 'data/sh/laws/*.html') {
Parse::parseHTMLSH($lawFile);
}
for my $lawFile (glob 'data/laws/*.html') {
Parse::parseHTML($lawFile);
}
while(my $shorthand = <STDIN>) {
chomp $shorthand;
my @law = grep { $_->{'veryshorthand'} eq $shorthand } values %{Parse::all()};
if(not @law) {
@law = grep { $_->{'name'} =~ /$shorthand/ or $_->{'shorthand'} =~ /$shorthand/ } values %{Parse::all()};
}
if(@law == 1) {
my $source = $law[0]->{'source'};
system("w3m '$source'");
} elsif(not @law) {
print "Not found: $shorthand\n";
} else {
print "Multiple matches: $shorthand\n";
foreach my $law (@law) {
print $law->{'veryshorthand'} . ": " . $law->{'name'} . "\n";
}
}
}