Specifically, I want to use rcols with the PERLCOLS option.
Here's what I want to do:
my @array;
getColumn(\@array, $file, 4); # get the fourth column from file
I can do it if I use \@array
, but for backward compatibility I'd prefer not to do this. Here's how I'd do it using an array-ref-ref:
sub getColumn {
my ($arefref, $file, $colNum) = @_;
my @read = rcols $file, { PERLCOLS => [$colNum] };
$$arefref = $read[-1];
return;
}
But, I don't see how to make a subroutine that takes an array ref as an argument without saying something like @$aref = @{$read[-1]}
, which, afaict, copies each element individually.
PS: reading the PDL::IO::Misc
documentation, it seems like the perl array ought to be $read[0]
but it's not.
PERLCOLS - an array of column numbers which are to be read into perl arrays rather than piddles. Any columns not specified in the explicit list of columns to read will be returned after the explicit columns. (default B).
I am using PDL v2.4.4_05 with Perl v5.10.0 built for x86_64-linux-thread-multi