Let's say that a SQL query returned the following data set:
't1' 'f1' 5
't1' 'f2' 5
't1' 'f3' 5
't2' 'f7' 7
't2' 'f8' 7
Now the first item of the list predicts the third item: I think that means they
have a functional relationship... f(column_one) = column_three will pass the
vertical line test. 't1' will always correspond to 5 and 't2' will always
correspond to 7.
Let's say that you want the compression of this data to be searchable by the
first field, hence you want a list in which each item is 3 boxes like so:
't1' ; (<('f1';'f2';'f3')) ; 5
't2' ; (<('f7';'f8')) ; 7
The reason I am asking is I could not help think that there was a far more
concise way of doing this in J than the equivalent Perl code:
# Read a row from the database query
while( my $data = $sth->fetchrow_hashref() ) {
# if the first column is already in the associative array
# (for the data above, if you have already seen t1 or t2)
if ( $w{$data->{white}} ) {
# add another item to the array of false words
# ie, go from 't1' ; (<('f1';'f2')) ; 5
# to 't1' ; (<('f1';'f2';'f3')) ; 5
push( @{$w{$data->{white}}->{fhl}}, $data->{black} );
}
# else create an output row
# ie, make 't1' ; (<('f1')) ; 5
else {
$w{$data->{white}} = {
watch_word => $data->{white},
fhl => [$data->{black}],
itemnumber => $data->{whitenum},
}
}
}
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm