Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, always start every script or module with:</p> <pre><code>use strict; use warnings; </code></pre> <p>You will get more warning messages and sooner, which greatly helps debugging.</p> <p>I cannot duplicate your error: when I put that code into a file and run it with no additional flags, I get: <code>size = , position =</code>. <strike>There is no <code>$size</code> variable in the code you printed, so </strike> the error message does not match.</p> <p>Nevertheless, you are declaring your data structures incorrectly. Hashes and arrays can only contain scalar values, not lists: so if you want to nest an array or a hash, you need to make it a reference. See <a href="http://perldoc.perl.org/perldata.html" rel="nofollow noreferrer">perldoc perldata</a>, <a href="http://perldoc.perl.org/perldsc.html" rel="nofollow noreferrer">perldoc perldsc</a> and <a href="http://perldoc.perl.org/perlreftut.html" rel="nofollow noreferrer">perldoc perlreftut</a> for more about data structures and references.</p> <pre><code>my %photo_details = ( black_cat =&gt; [ { size =&gt; '1600x1200', position =&gt; -25 }, { size =&gt; '1280x1024', position =&gt; 25 }, { size =&gt; '800x600', position =&gt; 0 }, ], race_car =&gt; [ { size =&gt; '1600x1200', position =&gt; 10 }, { size =&gt; '800x600', position =&gt; 5 }, ], ); foreach my $photo_detail (@{$photo_details{black_cat}}) { my $size = $photo_detail-&gt;{size}; my $position = $photo_detail-&gt;{position}; print ("size = $size, position = $position\n"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload