File: populateKeyword.pl

package info (click to toggle)
simpledb 1.5-1.4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze
  • size: 888 kB
  • ctags: 238
  • sloc: cpp: 529; makefile: 127; perl: 23; sh: 9
file content (28 lines) | stat: -rwxr-xr-x 499 bytes parent folder | download
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
#!/usr/bin/perl
sub usage {
  print "Usage: populateKeyword <keyword> <file>\n";
}

$keyword = shift or die usage();
$file = shift or die usage();

my $inMessage = 0;
while (<STDIN>) {
  if(index($_, "__END_".$keyword) != -1) {
    $inMessage = 0;
  }

  if(!$inMessage) {
    print $_;
  }

  $index = index($_, "__BEGIN_".$keyword);
  if($index != -1) {
    $inMessage = 1;
    $preLine = substr($_, 0, $index );
    open (FILE, $file);
    while (<FILE>) {
      print $preLine . $_;
    }
  }
}