On Fri, Apr 16, 2010 at 3:37 PM, Derek Lamb <[email protected]> wrote:

> I'm playing with the data from earlier today, the piddle:
>
> ...
>
> OK, fine, I need some quotes:
>
> perldl>  p pdl qw[1 0 8]
> [1 0 8]
>
>
> But how to do the 2D case?  About the closest I can get is this:
>
> perldl>  p pdl qw[
> ..[>   [1 0 8]
> ..[>   [6 3 5]
> ..[>   [3 0 5]
> ..[>   [2 4 2]
> ..[>  ]
> [0 0 8 0 3 5 0 0 5 0 4 2]
>
>
> It comes out 1D, and the first column is all zeroes.  Any tricks for
> making it come out 2D, or any ideas why the first column is all zeroes?
>

For anybody who might be confused, the problem here is how Perl interprets
the arguments. When Perl sees this:

@args = qw[
   [1 0 8]
   [6 3 5]
   [3 0 5]
   [2 4 2]
];

it considers everything within the outer pair of brackets as a string and
then chops it into pieces at the white space. As such, it converts that to a
flat array of strings with elements

@args = ( '[1', '0', '8]', '[6', ..., '2]')

Notice that the first argument is '[1', not '1', that is, it is a
two-character string consisting of a bracket and the number 1. When perl
evaluates this as a numeric value, it evaluates to zero. The last column
contains entries like '8]', which evaluates to the number 8. This is why all
of the elements in the left column of Derek's output are zero.

While we could try to write an extension to the function pdl() to properly
handle this (multiple string arguments which may or may not contain
brackets), it would be a lot easier to just pass a single stringified
argument, as Chris has proposed.

FYI :)
David
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to