#!/usr/bin/perl # PINSS.plx # Short for "Pins Is Not a Sentient Searcher" use strict; use warnings; sub pry; my $file_in; my $file_out; print "Please input the phrase or perl regular expression you want to use to begin capturing data: "; chomp(my $start_exp = ); print "Please input the phase or perl regular expression you want to use to cessate capture of data: "; chomp(my $stop_exp = ); if(scalar @ARGV > 1){ $file_in = shift @ARGV; $file_out = shift @ARGV; print "\nINPUT FILE: $file_in\n"; print "OUTPUT FILE: $file_out\n"; pry($file_in, $file_out, $start_exp, $stop_exp); print "\n\nSee $file_out for results\n\n"; }elsif(scalar @ARGV == 1){ $file_in = shift; print "Please specify an output file to print to (type 'screen' to print to terminal screen): "; chomp($file_out = ); print "\nINPUT FILE: $file_in\n"; print "OUTPUT FILE: $file_out\n"; pry($file_in, $file_out, $start_exp, $stop_exp); print "\n\nSee $file_out for results\n\n"; }else{ print "Please specify an input file to read from: "; chomp($file_in = ); print "Please specify an output file to print to (type 'screen' to print to terminal screen): "; chomp($file_out = ); print "\nINPUT FILE: $file_in\n"; print "OUTPUT FILE: $file_out\n"; pry($file_in, $file_out, $start_exp, $stop_exp); print "\n\nSee $file_out for results\n\n"; } sub pry(){ my $in_file = shift; my $out_file = shift; my $start = shift; my $stop = shift; # print "$in_file\n$out_file\n"; my $flag; open INFILE, $in_file or die "Cannot open input file to read from: $!"; if($out_file =~ m/screen/i){ *OUTFILE = *STDOUT; }else{ open OUTFILE, ">$out_file" or die "Cannot open output file to read from: $!"; } while(my $line = ){ chomp $line; next if $line =~ m/^\s*$/; # Skip all blank and whitespace only lines if ($flag){ if($line =~ m/$stop/){ $flag = 0; print OUTFILE "CAPTURE ENDED AT: $line\n"; next; } print OUTFILE "$line\n"; } if($line =~ m/$start/){ $flag = 1; print OUTFILE "\nCAPTURE STARTED AT: $line\n" } } close INFILE; return; } close OUTFILE;