in reply to File Filtering... Help

#!/usr/bin/perl -w my $file = shift; my $start = shift; my $end = shift; my $outfile = "$file.out"; open(IN, "<$file") || die "Can't open $file!\n"; open(OUT, ">$outfile") || die "Can't open $outfile!\n"; while(<IN>) { if (/$start(.*)$end/) { print OUT $1; } }
With your less-than-ample description, that's the best I can do in short order. Note that this code is completely *untested*, but shouldn't need too much messaging.

HTH.

Replies are listed 'Best First'.
Re^2: File Filtering... Help
by flounder99 (Friar) on Sep 12, 2003 at 18:31 UTC
    <massage> #!/usr/bin/perl -w use strict; my $file = shift; #always! my $start = quotemeta shift; #quote meta chars my $end = quotemeta shift; #quote meta chars my $outfile = "$file.out"; open(IN, "<$file") || die "Can't open $file!\n"; open(OUT, ">$outfile") || die "Can't open $outfile!\n"; my $file_contents = do {local $/; <IN>}; #slurp! while ($file_contents =~ /($start.*?$end)/gs) { print OUT $1, "\n"; } </massage> __infile__ blah blah blah #BG blah blah blah blah blah blah #EN blah blah blah blah #BG blah #EN blah blah blah blah __infile.out__ #BG blah blah blah blah blah blah #EN #BG blah #EN

    --

    flounder