Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3939766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:20:17+00:00 2026-05-20T00:20:17+00:00

I am trying to make an array of arrays and then reference them. I

  • 0

I am trying to make an array of arrays and then reference them.

I make somethign like:

sub foobar
{
 my @array;
 my $i;
 for ($i = 0; $i < 1000; $i=$i+1)
 {
  my @row;
  $row[0] = $i;
  $row[1] = foo($bar);
  push @array , [@row];
 }
 return \@array;
}

I can get to the values via:

$array->[x]->[y];

However I don’t understand why the second -> is needed. $array->[x] I understand because $array is a reference. But isn’t $array->[x] meant to be an array? Why doesn’t this work:

my @notarray = $array->[x];

What exactally is not array filled with now? Because it certainly doesn’t seem to be an array containing $i , foo($bar)

How would $array->[x]->[y] be different for a reference to an array of references to arrays?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:20:18+00:00Added an answer on May 20, 2026 at 12:20 am

    The second -> isn’t needed, actually.

    Here’s the deal: All Perl array values and hash values must be scalars. That means either a string, number, or array/hash reference (and not a plain old array or hash).

    So the first -> operator dereferences the array and gets at the x’th row. In there is– not an array, but an array reference. So in order to get to the data in there, you’d theoretically need another -> operator.

    But get this. Perl is smart: It knows that after one array or hash access, if another access happens, the only way this is possible is through an array/hash reference (because your first array/hash access MUST return a scalar)! So you don’t need the second arrow after all.

    See perldata for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to make an array-based linear list, then I compiled this: char
I'm trying to make an array, and then update the values of certain cells
I'm trying to make a dynamic array in C# but I get an annoying
I'm writing some error checking and trying to make use of an boolean array
I'm trying to subclass Array in ruby to make it randomize its elements when
Is there a way of printing arrays in C++? I'm trying to make a
I'm trying to make an array of integers in java but it won't work
I'm trying to make a deck of cards, with arrays for each suit in
I'm trying to make a variable sized array in c. The array keeps on
I am trying to make an app with two different tab bar controllers, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.