summaryrefslogtreecommitdiffstats
path: root/consume
blob: a180434e9a7bc1c11b35e3335861a977557d03b2 (plain)
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
38
39
#!/usr/bin/env perl

use Tie::File;
use IO::Handle;
$FPATH="$ENV{'HOME'}/logs/consume.log";

open OUTPUT, '>', $FPATH or die $!;
open ERROR,  '>', $FPATH  or die $!;

STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!;
STDERR->fdopen( \*ERROR,  'w' ) or die $!;

$filename=$ARGV[0];
#print $filename;
my @lines;
my $crumb;

tie @lines, 'Tie::File', $filename or die "Tieing failed : $!";
if (scalar(@lines) == 0){
    untie @lines;
    print "Gulp! Nothing more to consume";
    exit 127;
}

$counter = 0;
foreach(@lines){
    $counter++;
    if(/^[^%]/){
        # First non consumed line
        $crumb = $_; 
        s/^/%/;
        last;
    }
}
untie @lines;
#print $crumb;
chomp($crumb);
$crumb and system($crumb) == 0 or print "$crumb execution failed $!";