
December 7th, 2012, 06:33 AM
|
|
|
This could probably made somewhat simpler (avoiding nested while loops) with something like this (quick untested modification to Spacebar's code):
Code:
my $out;
my $outdir = '/temp/tmp/';
my $inf = '/temp/tmp/t2';
my $line;
open ( my $inf_fh, '<', $inf ) or die "Can't open $inf $!\n";
open (my $out_fh, '>', "dummy.txt" or die "$!\n";
while ( $line = <$inf_fh> ) {
if ( $line =~ /^Xcoor/) {
close $out_fh;
$out = substr( $line, 0, -1 );
$out =~ s/\s+$//;
open ( my $out_fh, '>', "${outdir}${out}.txt" ) or die "Can't open ${outdir}${out}.txt $!\n";
}
print $out_fh $line;
}
close $out_fh;
|