Hi
I have a file containing arrays of numbers. I 'm trying to get a
subroutine iterate the file and print ONLY arrays with three elements
into a second file. None of the elements has more than 2 digits. So I
tried with a pattern match, it fails to deliver the right result.
I want it to find and print array with 3 elements like:
1 2 5
20 33 45
5 17 25
sub get_arr{
open (OUTPUT, "permed.dat") || die "Could not open file. $! \n";
open (INPUT, ">cleaned_up.dat") || die "Could not open file. $!
\n";
my ($clean, @clean, $cleanprint, $arrlength, $result);
$clean = <OUTPUT>;
while ( $clean ){
@clean = split (" ", $clean);
print INPUT ("@clean") if (@clean =~
/\d+\s+\d+\s+\d+/);
$clean = <OUTPUT>;
}
die ("Could not close output file. $! \n") unless close
(OUTPUT);
die ("Could not close input file. $! \n") unless close (INPUT);
}
Thanks
B. Fongo