in reply to create separate output files based on the matched values
unpack is great for fixed width fields.
# @fields = unpack('a5 a6 a7 a5', $_); # @fields = unpack('a4 x1 a5 x1 a6 x1 a5', $_); open(my $fh_in, '<', ...) or die("Can't open input file: $!\n"); while (<$fh_in>) { chomp; my ($file_name, $rest) = unpack('a4 x1 a*', $_); $file_name .= '.out'; open(my $fh_out, '>>', $file_name) or die("Can't open $file_name for append: $!\n"); print $fh_out ("$rest\n"); }
By the way, your data is not fixed width. The 5th record is shorter.
|
|---|