It seems to me the problem is a little simpler than your code makes it. Wouldn't this do it?
use strict; use warnings; while( <> ) { chomp; # Test for validity of input, and capture significant digits. # If input seems invalid, die. unless( m/^(?:2|42) # Match but don't capture your prefix. (\d{11})\s # Match and capture left-grouping of digits. (\d{13})\s # Match and capture mid-grouping of digits. (\d3)/x # Match and capture right-grouping of digits. ) { die "Improperly formatted input data:\n\tLine: $.\t$_\n"; } my( @columns ) = ( $1, $2, $3 ); # Retain the captures. # Look for "reject" codes. next if $columns[1] =~ m/^\d{6}(?:406|408)\d{4}\s$/; # Print a nicely formatted result. print "CH $columns[0] $columns[1] $columns[2] LAB\n"; }
I didn't test the regexps, so you may need to adjust the quantifiers, but they look right to me. From the command line type 'scriptname infile.data >outfile.data', where 'infile.data' is the filename of your input, and 'outfile.data' is the filename of your output. You could deal with opening and closing filehandles in-script, but it's probably not necessary unless you don't want to use redirection at the OS level.
Dave
In reply to Re: Removing element of an array
by davido
in thread Removing element of an array
by cesear
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |