Playing with the input record separator so that you're reading in records where the separator is .slow can simplify things a little. This way you're reading 'records' rather than lines, so you don't have to worry about keeping track of state flags.
use strict; use warnings; my $in_file_name = 'sample.txt'; { local $/ = '.slow'; open my $input, '<', $in_file_name or die $!; while( my $rec = <$input> ) { chomp $rec; next unless $rec =~ m/(\d+)\.pace(.+)$/s; my( $out_file_name, $capture ) = ( $1, $2 ); open my $output, '>', $out_file_name or die $!; print $output $capture; close $output or die $!; } close $input; }
Untested. But I think it gets the idea across.
Dave
In reply to Re: copying lines in a text file to a new file with a dynamically generated text name
by davido
in thread copying lines in a text file to a new file with a dynamically generated text name
by seek_m
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |