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

  • Home
  • SEARCH
  • 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 8520655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:35:39+00:00 2026-06-11T06:35:39+00:00

The top answer in this post: How can I create a multidimensional array in

  • 0

The top answer in this post: How can I create a multidimensional array in Perl? suggests building a multi-dimensional array as follows:

my @array = ();
foreach my $i ( 0 .. 10 ) {
  foreach my $j ( 0 .. 10 ) {
    push @{ $array[$i] }, $j;
  }
}

I am wondering if there is a way of building the array more compactly and avoiding the nested loop, e.g. using something like:

my @array = ();
my @other_array = (0 ... 10);
foreach my $i ( 0 .. 10 ) {
    $array[$i] = @other_array; # This does not work in Perl
  }
}

Does Perl support any syntax like that for building multi-dimensional arrays without nested looping?

Similarly, is there a way to print the multidimensional array without (nested) looping?

  • 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-06-11T06:35:41+00:00Added an answer on June 11, 2026 at 6:35 am

    There is more than one way to do it:

    Generating

    push accepts LISTs

    my @array;
    push @{$array[$_]}, 0 .. 10 for 0 .. 10;
    

    Alternative syntax:

    my @array;
    push @array, [ 0 .. 10 ] for 0 .. 10;
    

    map eye-candy

    my @array = map { [ 0 .. 10 ] } 0 .. 10;
    

    Alternative syntax:

    my @array = map [ 0 .. 10 ], 0 .. 10;
    

    Printing

    With minimal looping

    print "@$_\n" for @array;
    

    On Perl 5.10+

    use feature 'say';
    say "@$_" for @array;
    

    With more formatting control

    print join( ', ', @$_ ), "\n" for @array;   # "0, 1, 2, ... 9, 10"
    

    “No loops” (The loop is hidden from you)

    use Data::Dump 'dd';
    dd @array;
    

    Data::Dumper

    use Data::Dumper;
    print Dumper \@array;
    

    Have a look at perldoc perllol for more details

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

Sidebar

Related Questions

I just read the top answer at this post: Problem inserting string or NULL
I recently learned about strides in the answer to this post , and was
While commenting on an answer in this other SO post , the point came
In Hidden Features of Java the top answer mentions Double Brace Initialization , with
WITH TOP 100000 (100k) this query is finished in about 3 seconds WITH TOP
I need to call this method, but I can't find it in any namespace.
Top post update: unacceptably slow means between 2 and 10 seconds to load the
I can't get @font-face working in any browser on macs. I believe this is
Please review this Stackoverflow post. I have the same PHP problem as bob_cobb. Here's
Update: NSURLConnection now seems to properly support 100-Continue. In any case, this answer contains

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.