Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Another "Can't use string as an ARRAY ref"

by hippo (Bishop)
on Dec 05, 2016 at 14:07 UTC ( [id://1177214]=note: print w/replies, xml ) Need Help??


in reply to Another "Can't use string as an ARRAY ref"

Your useful print statement shows you that $plants->[$i]{'common'} has value "State Street Miyabe Maple". What then do you intend this expression from the following line to do?

$plants->[$i]{'common'}->[$jctr]{'sizes'}

That's clearly the equivalent of:

"State Street Miyabe Maple"->[$jctr]{'sizes'}

which is nonsense. You cannot dereference a scalar string like that. Does that make it clearer to you?

Replies are listed 'Best First'.
Re^2: Another "Can't use string as an ARRAY ref"
by bradcathey (Prior) on Dec 05, 2016 at 14:54 UTC

    Brilliant. I'm a visual learner and this was very helpful. Now to figure out a solution. More to come...

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

      You might want to consider a simpler more SQL solution

      #!perl use strict; use DBI; use Data::Dumper; my $dbh = create_db(); my $sql = 'SELECT P.common_name,S.plant_size,S.unit,G.abbr FROM plants as P LEFT JOIN sizes as S ON S.plantid = P.id LEFT JOIN growers as G ON S.plantid = G.plantid AND S.plant_size = G.plant_size'; my $sth = $dbh->prepare($sql); $sth->execute(); my %hash=(); while (my @f = $sth->fetchrow_array){ $hash{$f[0]}{$f[1].$f[2]}{$f[3]} = 1 } print Dumper(\%hash);
      poj

        I appreciate the SQL approach. It's so much easier the building stuff in raw Perl. My SQL chops aren't what yours are, but I'm going to dissect this to see how it works. Thanks.

        —Brad
        "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found