Skip to content

Commit 8f13918

Browse files
committed
refactoring rules!
1 parent dd68d17 commit 8f13918

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

dupplot-on-dupplot-refactored.png

7.14 KB
Loading

dupplot-on-dupplot.png

8.53 KB
Loading

dupplot2.pl

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/perl
2+
# Usage ./dupplot.pl file1 file2 >/tmp/data ;
3+
# gnuplot, and type: set title "My Plot"; plot '/tmp/data'
4+
# Author Raimon Grau <[email protected]>. Artistic License v2.0
5+
6+
use strict;
7+
use warnings;
8+
use Data::Dumper;
9+
use Digest::MD5;
10+
use File::Basename;
11+
12+
sub say {print @_,"\n";}
13+
14+
my %sanitizer = (".pl" => sub { $_ = shift; $_; },
15+
".rb" => sub {
16+
$_ = shift;
17+
s/^\s*end\s*$//;
18+
$_;
19+
},
20+
".lisp" => sub {
21+
$_ = shift;
22+
s/;.*//;
23+
s/\)+$/\)/;
24+
$_;
25+
}
26+
);
27+
28+
sub extension_for {
29+
my $fn = shift;
30+
my ($name, $dir, $ext) = fileparse($fn, qr/\.[^.]*/);
31+
return $ext;
32+
}
33+
34+
my %h = ();
35+
my @tuples = ();
36+
37+
sub process_file {
38+
my ($fn, $sub) = (shift, shift);
39+
40+
open(my $fh, "<", $fn)
41+
or die "Can't open < input.txt: $!";
42+
my $ext = extension_for($fn);
43+
44+
my $md5;
45+
while(<$fh>){
46+
chomp;
47+
48+
$_ = $sanitizer{$ext}->($_) if exists $sanitizer{$ext};
49+
50+
next if /^\s*$/;
51+
$md5 = Digest::MD5::md5_hex($_);
52+
$sub->($md5);
53+
}
54+
close $fn;
55+
return;
56+
}
57+
58+
process_file(shift, sub { push @{$h{$_}}, $.;});
59+
process_file(shift,
60+
sub {
61+
for (@{$h{$_}}) {
62+
push @tuples, [$. , $_];
63+
}
64+
});
65+
66+
for my $tuple (@tuples) {
67+
say $tuple->[0], " " , $tuple->[1] ;
68+
}

0 commit comments

Comments
 (0)