Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: array to string

by davido (Cardinal)
on Oct 13, 2020 at 17:29 UTC ( #11122778=note: print w/replies, xml ) Need Help??


in reply to array to string

What happens when you use Data::Dumper and dump $Count?

use Data::Dumper; # do your select.... # then... print Dumper $Count;

If there's a misunderstanding about the data structure that is making it hard to print it, this will given you insight.


Dave

Replies are listed 'Best First'.
Re^2: array to string
by bigup401 (Pilgrim) on Oct 13, 2020 at 17:46 UTC

    thank you

Re^2: array to string
by bigup401 (Pilgrim) on Oct 13, 2020 at 17:54 UTC

    one thing confuses me is that the query is ok, but perl not coverting into to string and print out, because when i use data dumper to print info, there no problem info comes

    i tried to select with the actual location and results came

    $VAR1 = [ [ 1 ] ]; Content-type: text/html

    other country with no location also results come ok

    $VAR1 = [ [ 0 ] ]; Content-type: text/html

      What you've got there is an array reference with one element, which is another array reference with a single element. Change your code to this:

      for my $total_info(@$Count) { print "$total_info->[0]\n"; }

      In the for statement, you extract a single element of the array in a loop (the inner array reference). The print statement prints out the first element of the inner array reference.

      Will you ever get more than one record returned per call? If not, you might consider not using fetchall_arrayref, as that's why you have an aref inside of a top-level aref. fetchall_* implies that you're expecting several records returned. If you only ever expect one piece of data returned per call, use fetchrow_arrayref.

        The output of SELECT COUNT(*)... should always be a single number, so the outer foreach is probably unnecessary:

        print "$Count->[0]->[0]\n";

        Dave

        For SELECT COUNT(*) FROM ... and similar queries that can only return a single value in a single row, the selectrow_array method can directly return the desired information, instead of wrapping it into an arrayref. The DBI documentation has more details, including using that method with previously prepared statements.

        thanks guys

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11122778]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2021-01-17 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?