The problem is that '$array' is not an array; it's an array reference - similar to a pointer. Your code seems fine, all except for that point. Quick overview of dealing with array references:

# Turning an arrayref into an array my @arr = @$aref; # Extracting a single value from an arrayref print ${$aref}[0]; # Or, more readable and less problematic: print $aref -> [0]; # Looping over the pointed-to list for my $i (@$aref){ ... }

In the above case, the structure that you're getting back from 'Range()' is an "AoA" - an array of arrays - which looks like this:

$aref = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ];

Notice the second level of indirection, there? The result is that just converting the ref to an array is going to give you a list of... arrayrefs, which need to be expanded into arrays. The solution that netwallah shows is correct - I just wanted to give you a more general heads-up for this kind of problem. So, expanding the above looks like this:

for my $deref (@$aref){ for my $element (@$deref){ print "$element\n"; } }

Again, for more on data structures - AoAs, HoHs, etc. - see perldoc perlref and the excellent Data Structures Cookbook.

-- 
I hate storms, but calms undermine my spirits.
 -- Bernard Moitessier, "The Long Way"

In reply to Re: How can I access the values of an "array" extracted using Range by oko1
in thread How can I access the values of an "array" extracted using Range by ralph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.