/[Sack]/trunk/bin/sack.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/bin/sack.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Sun Sep 20 20:08:11 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1574 byte(s)
configurable --path, --offset and --limit

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Time::HiRes qw(time);
7 use Data::Dump qw(dump);
8 use File::Slurp;
9 use Getopt::Long;
10
11
12 my $path = '/data/isi/full.txt';
13 my $limit = 10000;
14 my $offset = 0;
15
16
17 GetOptions(
18 'path=s' => \$path,
19 'offset=i' => \$offset,
20 'limit=i' => \$limit,
21 );
22
23 my $t = time;
24
25 use lib '/srv/webpac2/lib/';
26 use WebPAC::Input::ISI;
27 my $input = WebPAC::Input::ISI->new(
28 path => $path,
29 offset => $offset,
30 limit => $limit,
31 );
32
33
34 sub report {
35 my $description = shift;
36 my $dt = time - $t;
37 printf "%s in %1.4fs %.2f/s\n", $description, $dt, $input->size / $dt;
38 }
39
40
41 report $input->size . ' records loaded';
42
43 mkdir 'out' unless -e 'out';
44
45 sub run_views {
46 my @views = glob 'views/*.pl';
47 warn "# views ", dump @views;
48
49 foreach my $view ( @views ) {
50
51 my ( $nr, $package ) = ( $1, $2 )
52 if $view =~ m{/(\d+)\.([^/]+(\.pl)?$)};
53
54 my $out;
55
56 next if system("perl -c $view") != 0;
57
58 my $code = read_file $view;
59 warn $code;
60
61 $t = time;
62
63 foreach my $pos ( 1 .. $input->size ) {
64 my $rec = $input->fetch_rec($pos);
65
66 eval $code;
67 die "ERROR [$pos] $@" if $@;
68 };
69
70 report $view;
71
72 if ( defined $out ) {
73 my $dump = dump $out;
74 my $len = length $dump;
75 my $path = "out/$nr.$package";
76 print "# $view $offset/$limit $len bytes $path"
77 , $len < 10000 ? " \$out = $dump" : ' SAVED ONLY'
78 , "\n"
79 ;
80 write_file $path, $dump;
81 report "save $path";
82 }
83
84 }
85 }
86
87 run_views;
88
89 while ( 1 ) {
90
91 print "sack> ";
92 my $cmd = <STDIN>;
93
94 if ( $cmd =~ m{(vi|\\e|out)}i ) {
95 system "vi out/*";
96 } else {
97 run_views;
98 }
99
100 }
101

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26