Perl Mojolicious array loop

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Perl Mojolicious array loop



Not sure if this is even possible. But I am trying to loop over an array. I keep getting the error message Can't use an array as a reference on the for loop line. $product_results->[6] does contain data.


Can't use an array as a reference


$product_results->[6]


my @product_array = split(',', $order->[6]);
$product_results->[6] = @product_array;
% for (@$product_results->[6])
<%= $_->[0] %>
%





@$product_results->[6] should work.
– Rajashekar Reddy M
Aug 10 at 10:49





Thanks that worked.
– user3525290
Aug 10 at 11:07





@RajashekarReddyM next time, write an answer to get some rep. Don't answer in comments. ;)
– simbabque
Aug 10 at 11:08




1 Answer
1



You are using both forms of dereferencing at once.



Either use


$ref->[6];



or


@$ref[6];



Both at the same time will Perl dereference the reference as an array into something like this, and then dereference that as an array reference to get the 7th element. But that doesn't work.


(1, 2, 3)->[7]



What you actually want to do is dereference the array ref that is inside your seventh index in the array reference.


# this will deref the content of index 7
# | this will deref $ref into an array
# | |
@ $ref->[7]



To illustrate forther, your data structure looks like this.


$ref = [
0,
1,
2,
3,
4,
5,
6,
[ # 7
qw/ foo bar baz/
],
]






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard