in reply to Re^4: regular expessions question: (replacing words)
in thread regular expessions question: (replacing words)
Does your data fit into memory? If not, it gets more complicated (or you just have to wait a long time for the data file to get read dozens of times). You would either have to store it into a database or compress it (i.e. 'z' is 1, not-z is 0, so that every element uses just one bit)
If yes, read the file into an Array of Arrays:
my @data; my $n=0; while ($organized=<DATA2>) { chomp; $organized=~s/(\s)\w+/$1z/g; push @{$data[$n++]}, (split /\s+/, $organized); }
Now accessing column 5 of line 2 is just a simple $data[2][5]
Now to get it easier, split your problem into easier parts. Create a subroutine that gets as parameter an arbitrary number of columns. This subroutine just counts all rows that have a 'z' in all these columns. You can do that with a loop (over the selected columns) inside a loop (over all rows).
If you got that working (test it with some simple data), just create another array, add a random number. Then repeatedly add a random number (that is not already in the array) to the array, call the subroutine with it. Do that 18 times.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: regular expessions question: (replacing words)
by $new_guy (Acolyte) on Sep 28, 2010 at 07:28 UTC | |
by jethro (Monsignor) on Sep 28, 2010 at 22:44 UTC |