use PDL; use PDL::IO::Export2D; my $pdl = rvals(6,4); open my $fh, '>', 'file.dat'; $pdl->export2d($fh);
This module has be superceded (and indeed is now provided by) the PDL::Util module. This module is kept for backwards compatibility for now, though I doubt many people were using it before this inclusion. For now it still works as described herein.
Provides a convenient method for exporting a 2D piddle.
export2d is a wrapper around the standard
wcols for exporting the entire piddle; use it to write to a 2D piddle as a CSV or other simple ASCII data format quickly and painlessly. The author was tired of having to extract the columns just to write them all to a file.
export2d may take up to 2 optional arguments, a lexical filehandle (or globref, e.g.
\*FILE) to write to, and a string containing a column separator. The defaults, if arguments are not given are to print to STDOUT and use a single space as the column separator. The order does not matter, the method will determine whether an argument refers to a file or not. This is done so that one may call either
and it will do what you mean. Unfortunately this means that unlike
wcols one cannot use a filename rather than a filehandle;
export2d would interpret the string as the column separator!
The method returns the number of columns that were written.
The method is pushed into the
PDL namespace. Should
PDL ever provide method of the same name, this module will override it, warning with both the standard Perl redefinition warning as well as an additional message from the package. To avoid a conflict a different method name may be passed when loading the module. For example:
use PDL::IO::Export2D 'my_export';
causing the method provided by this module to be called as
rather than the default name
Joel Berger, <email@example.com>
Copyright (C) 2011 by Joel Berger
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.