in reply to Fast Matrix Load

Well, you don't tell us anything about the file, but if it's comma delimited, then perhaps this:
#!/usr/bin/perl -w use strict; use warnings; # create array ref and count my $matrix=(); my $i=0; open PROFILES, 'profile/profile.db' or die $!; while (<PROFILES>) { chomp; # add array as array ref to array ref @{$matrix->[$i]} = split /\t/; $i++; } close(PROFILES); # access referenced data like this print $matrix->[1]->[6]; # (7th element of 2nd row generally :) # should start at 0,0 exit(0);

cLive ;-)

Update: since you've added more info, I've updated above to reflect your existing code..

--
seek(JOB,$$LA,0);

Replies are listed 'Best First'.
Re: (cLive ;-) Re: Fast Matrix Load
by Evanovich (Scribe) on Feb 17, 2002 at 03:43 UTC
    Well, that might help, except that there's one caveat. I'm passing this matrix to a C routine. Here's how it works, once I build the matrix @matrix as shown earlier:
    anglecast (@matrix); sub anglecast (\@) { my $avMatrix = shift (@_); my $packedMatrix= ""; my @recycleBin; my $width= @{$avMatrix->[0]}; for my $avRow(@$avMatrix) { $width= @$avRow if @$avRow<$width; my $packedRow= pack("f$width", @$avRow); push @recycleBin, \$packedRow; $packedMatrix .= pack("P", $packedRow); } return CAST(0+@$avMatrix, $width, $packedMatrix); } Anyone know how to modify this if I want to use references? Or maybe +there's a more efficient way to load a matrix? Thanks again, Evan
      The quickest solution I can think of (without trying to understand your code), is to dereference the array as you send it to the sub, ie:
      anglecast (@{$matrix});

      cLive ;-)

      --
      seek(JOB,$$LA,0);