filter.pl 517 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/perl
  2. # we want to filter every between START_INS and END_INS out and then insert crap from another file (this is fun)
  3. $dst = shift;
  4. $ins = shift;
  5. open(SRC,"<$dst");
  6. open(INS,"<$ins");
  7. open(TMP,">tmp.delme");
  8. $l = 0;
  9. while (<SRC>) {
  10. if ($_ =~ /START_INS/) {
  11. print TMP $_;
  12. $l = 1;
  13. while (<INS>) {
  14. print TMP $_;
  15. }
  16. close INS;
  17. } elsif ($_ =~ /END_INS/) {
  18. print TMP $_;
  19. $l = 0;
  20. } elsif ($l == 0) {
  21. print TMP $_;
  22. }
  23. }
  24. close TMP;
  25. close SRC;