The stupid question is the question not asked | |
PerlMonks |
Unexpected behavior when using PDL::IO::Misc::rcols with $PDL::undefvalby kevbot (Vicar) |
on Jul 30, 2012 at 03:42 UTC ( [id://984338]=perlquestion: print w/replies, xml ) | Need Help?? |
kevbot has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am using PDL in some modules, and I want to import numerical data from a text file using the rcols function found in PDL::IO::Misc. The rcols function will import the text file into piddles that correspond to the columns of the text file. I stumbled across an issue when I was trying to import data from a tab-delimited text file. Some positions in my input data file will contain blank entries. It seems that handling of blank entries is inconsistent. If a blank entry is in the last column of the file then the $PDL::undefval is used in the piddle. If a blank appears elsewhere, then it appears that a value of "0" is used in the piddle. Here is an example.
I have two data files. The data.txt file is tab-delimited and does not contain blank entries.
The data_missing.txt file is tab-delimited but contains some blank entries. I use the following script to test the contents of the pdls created by rcols: The output for <data.txt> is: The output for <data_missing.txt> is: So far, so good. However, if I change the value for $PDL::undefval, I get a strange result. First, the default value of $PDL::undefval is zero. Here is the code with $PDL::undefval set to -999. The output for <data.txt> is: The output for <data_missing.txt> is: The value of $PDL::undefval is used in one case (where the 12 was deleted at the end of a row in the input file), but a zero used (where the 9 was deleted in the middle of a row in the input file). This looks like a bug to me. Does anyone else have experience using this feature of PDL?
Back to
Seekers of Perl Wisdom
|
|