Evanovich has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys--I'm wondering if you can help me with a basic problem regarding Perl Data Language (PDL). I'm trying to figure out how to read a 2D array of numbers into a piddle so I can do some speedy calculations on it. I tried the following, but I get an error:
#! /usr/bin/perl -w use strict; use PDL; open PROFILE, "profile" or die "Could not open\n"; my $array_ref; while (<PROFILE>) { push (@{$array_ref}, $_); } my $pdl = pdl($array_ref); print "$pdl\n":
The print does not yield my array, and I get the following error:
Argument "\x{30}\x{2e}..." isn't numeric in subroutine entry at /usr/l +ib/perl5/site_perl/5.8.0/i386-linux-thread-multi/PDL/Core.pm line 570 +, <PROFILE> line 1.
If anyone can help me out with this, i'd really appreciate it.

Replies are listed 'Best First'.
Re: Perl Data Language Question
by chromatic (Archbishop) on Apr 01, 2003 at 03:02 UTC

    You'll probably have to show an example of the data in profile. For starters, PDL might be choking on newlines. Throw a chomp in the loop before the push.

Re: Perl Data Language Question
by graff (Chancellor) on Apr 01, 2003 at 03:19 UTC
    Argument "\x{30}\x{2e}..." isn't numeric (etc.)

    Is that really all there is to the error message, or did you leave out some of the stuff between quotes, for brevity? (What the quoted part says is that the arg had an ASCII "0" character, followed by an ASCII period character, followed by something else, and maybe it's the "something else" (where you have "...") that is making it hard to see the data as numeric.)

    Chromatic is right -- seeing at least line 1 of "profile" will be helpful -- and if there's something other than those three periods in the error report that you posted, that would help as well.

    FWIW, I made up a file with the numbers 1 .. 10 (and 1.0 .. 10.0, with both unix and dos line terminations, and ran it through just like you did, and had no problem -- it always printed quite nicely. So maybe your data is different somehow.

    (And thanks for getting me acquainted with PDL -- looks totally awesome, and I'm gonna love it!)

Re: Perl Data Language Question
by pg (Canon) on Apr 01, 2003 at 03:48 UTC
    "\x{30}\x{2e}" is "0.", so it is numeric. There must be some garbage characters in your data?
      DOH! I'm sorry guys. It looks like I had some tabs in there I forgot to take out. Thanks for all your help though.
Re: Perl Data Language Question
by belg4mit (Prior) on Apr 01, 2003 at 03:17 UTC
    You need to initialitze your array_ref
    my $array_ref = [];

    --
    I'm not belgian but I play one on TV.

      It would make for good hygiene/habits to initialize that way, but it's not mandatory (and probably won't make a difference in this case); the following works with no sweat:
      use strict; use PDL; my $arref; while(<DATA>) { push @$arref, $_; } my $p = pdl($arref); print $p,$/; __DATA__ 1.0 2.2 3.1 4.0 5.5 10.0 20.0
        Doh, yeah... so used to -w

        --
        I'm not belgian but I play one on TV.