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

Hello all you venerable monks,

I have a quickie question about the selectall_arrayref method, here's my MSSQL query from my sparc/linux box:

my $query1 = " select \"column1\", \"column2\" from Database.Table where \"column +1\" in ($values_string) and \"column3\" != '2' ";

I'm trying to execute the code by the selectall_array method in the following way:
my $dsn2 = 'DBI:Sybase:server=xx.xx.xx.xx'; my $dbh2 = DBI->connect($dsn2, "user", 'pass'); die "unable to connect to server $DBI::errstr" unless $dbh2; my $values_array=${$dbh2->selectall_arrayref($query1)}; while (my $row = shift(@$values_array)) { print "row->[0], row->[1]\n"; }
And get the following error:

Not a SCALAR reference at line 108


Maybe there's an easy solution to this problem, but i still didn't find out..

Thanks

F

Replies are listed 'Best First'.
Re: DBD::Sybase, selectall_arrayref "Not a SCALAR reference" error
by Corion (Patriarch) on Jun 22, 2009 at 13:31 UTC

    You didn't tell us what line 108 is in your code, but I'm sure when you go and look, it will be this line:

    my $values_array=${$dbh2->selectall_arrayref($query1)};

    This is because $dbh2->selectall_arrayref($query1) does return a reference to an array, and not a scalar. Did you mean

    my $values_array = $dbh2->selectall_arrayref($query1)
    ?

Re: DBD::Sybase, selectall_arrayref "Not a SCALAR reference" error
by Transient (Hermit) on Jun 22, 2009 at 13:32 UTC
    my $values_array=${$dbh2->selectall_arrayref($query1)};
    is trying to tell Perl that the return value for selectall_arrayref is a scalar reference, which it isn't. Changing this to:
    my $values_array=$dbh2->selectall_arrayref($query1);
    should fix that particular problem. You don't need to tell Perl what kind of reference is being returned until you access it.
      Thanks Corion and Transient, yes the solution was immediate!
Re: DBD::Sybase, selectall_arrayref "Not a SCALAR reference" error
by Anonymous Monk on Jun 22, 2009 at 13:35 UTC
    Which line is line 108?
    print "row->[0], row->[1]\n";
    row is not $row
    echo Not a SCALAR reference at -e line 108 |splain Not a SCALAR reference at -e line 108 (#1) (F) Perl was trying to evaluate a reference to a scalar value, but + found a reference to something else instead. You can use the ref() func +tion to find out what kind of ref it really was. See perlref.
    use DBI->quote or see What are placeholders in DBI, and why would I want to use them?
      Thanks Anonymous Monk, yes $row.. a typo error and too much of that tiredness :)