CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Can't use string as a HASH ref

 



MattC
Novice

Nov 2, 2012, 11:30 AM

Post #1 of 8 (1798 views)
Can't use string as a HASH ref Can't Post

Getting an error at work today:
Can't use string as a HASH ref



Code
 if ($sph_results->{total_found}) { 
my @docid = map $_->{doc}, @{ $sph_results->{matches} };
my %get_all_params = (
cache => $c->cache,
bypass_cache => $c->req->param('bypass_cache') || 0,
schema => $c->model('DB'),
user_exists => $c->user_exists() || 0,
is_movie => $c->stash->{is_movie} || 0,
config => $c->config,
images_dir => $c->path_to(qw[ root static images ]),
);
if($get_all_params{user_exists}) {
$get_all_params{user_id} = $c->user->get('id');
}
my $documents = $c->model('DB::Document')->get_all_data_related_to_document_array(\@docid, \%get_all_params, $c);

# fill $documents with image proportions here
if($documents->[0]{document_type_name} eq 'photos' || $c->stash->{filter} eq 'photos') {

my $max_width = 750;
my $photos_per_row = 3;

my $document_chunks = [];
while( my @list = splice( @$documents, 0, $photos_per_row ) ) {
push @$document_chunks, \@list;
}

foreach my $documents (@$document_chunks) {
my $largest_height = 0;
foreach my $document (@$documents) {
if($document->{photos}[0]{large_photo}{height} > $largest_height) {
my $height = $document->{photos}[0]{large_photo}{height};
$largest_height = $height;
}
}

my $total_width = 0;
foreach my $document (@$documents) {
my $height = $document->{photos}[0]{large_photo}{height};
my $width = $document->{photos}[0]{large_photo}{width};

if($height) {
my $scale_factor = $largest_height / $height;

$document->{photos}[0]{large_photo}{scaled_height} = $height * $scale_factor;
$document->{photos}[0]{large_photo}{scaled_width} = $width * $scale_factor;

$total_width += $document->{photos}[0]{large_photo}{scaled_width};
}
}

foreach my $document (@$documents) {
my $height = $document->{photos}[0]{large_photo}{scaled_height};
my $width = $document->{photos}[0]{large_photo}{scaled_width};
if($width) {

my $percent = $width / $total_width;

$document->{photos}[0]{large_photo}{scaled_width} = int($max_width * $percent);
my $scale_factor = $document->{photos}[0]{large_photo}{scaled_width} / $width;

$document->{photos}[0]{large_photo}{scaled_height} = int($height * $scale_factor);
}
}

push @{ $c->stash->{document_blocks} }, $documents;

}

}



FishMonger
Veteran / Moderator

Nov 2, 2012, 11:35 AM

Post #2 of 8 (1795 views)
Re: [MattC] Can't use string as a HASH ref [In reply to] Can't Post

Which line is the warning referring to?


MattC
Novice

Nov 2, 2012, 11:37 AM

Post #3 of 8 (1793 views)
Re: [FishMonger] Can't use string as a HASH ref [In reply to] Can't Post

This is the line warnings are popping up on:


Code
 if($documents->[0]{document_type_name} eq 'photos' || $c->stash->{filter} eq 'photos') {



FishMonger
Veteran / Moderator

Nov 2, 2012, 11:43 AM

Post #4 of 8 (1790 views)
Re: [MattC] Can't use string as a HASH ref [In reply to] Can't Post

You should use Data::Dumper to dump out those 2 data structures to see if their format is what you expect.

I suspect the problem is with this:

Code
$c->stash->{filter}

It probably should be:

Code
$c->{stash}{filter}



MattC
Novice

Nov 2, 2012, 11:59 AM

Post #5 of 8 (1787 views)
Re: [FishMonger] Can't use string as a HASH ref [In reply to] Can't Post

I figured it out, also now getting an error on Line 500, which is:

Code
if($document->{photos}[0]{large_photo}{height} > $largest_height) {



FishMonger
Veteran / Moderator

Nov 2, 2012, 12:01 PM

Post #6 of 8 (1785 views)
Re: [MattC] Can't use string as a HASH ref [In reply to] Can't Post

The same error or something different?


MattC
Novice

Nov 2, 2012, 12:01 PM

Post #7 of 8 (1783 views)
Re: [FishMonger] Can't use string as a HASH ref [In reply to] Can't Post

Same error.


FishMonger
Veteran / Moderator

Nov 2, 2012, 12:05 PM

Post #8 of 8 (1781 views)
Re: [MattC] Can't use string as a HASH ref [In reply to] Can't Post

Are you sure $document has the structure you think? Dump it out to verify the structure.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives