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 8923255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:04:22+00:00 2026-06-15T07:04:22+00:00

I have 7 arrays that are defined in the following manner: my @array1 =

  • 0

I have 7 arrays that are defined in the following manner:

my @array1 = ();
..
my @array7 = ();

and then:

$array1[0] = "text goes here";
..
$array7[0] = "text goes here";

There are about 25 elements) in each of the seven arrays, that is, $array1[0] to $array1[24]. I need to frequently change the content of these arrays in various scripts. And sometimes, because the order of the arrays is essential, I need to rearrange the order of the array index or delete the elements at a position. This is a real pain in the ass, as I need to change the index of all subsequent arrays. Just to make it clear, if I delete array1[12], then I need to change $array1[13] to $array1[12] and that for all 7 arrays and for all subsequent index positions (or move the content of array1[13] to array1[12], etc.)

So my question is, is it possible to impute the index of the arrays so that I could switch around the arrays position without having to correct each array index afterwards? Something like this:

$array1[$_] = "text 1 goes here";
..
$array7[$_] = "other text 1 goes here";

and then:

$array1[$_] = "text 2 goes here";
..
$array7[$_] = "other text 2 goes here";

where $_ would be replaced by 1 for the first index of each of the 7 arrays and by 2 for the next element of each of the 7 arrays… (up to 24 elements).

Is there a solution to this problem other than using an hash and Tie::Hash?

EDIT
ok, let me clarify. I am looking for a script maintenance solution, no for a solution about the output of the script. I need to change the script myself (by hand) frequently and I do not want to change the numbers indexing all 24 positions of all 7 arrays by hand whenever I change something in these arrays. So my question was, is there a way to have the script impute the numbers indexing all positions of all arrays?

Using push as mvp was suggesting would be a proper solution. Are there any other solutions that could involve loops or something rather than using push 7X24 times?

  • 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-15T07:04:24+00:00Added an answer on June 15, 2026 at 7:04 am

    You can use this approach:

    my @array1;
    push @array1, "text 1 goes here";
    push @array1, "other text 1 goes here";
    # ...
    # or you can use loop as well:
    for my $i (1..10) {
        push @array1, "text 1 instance $i goes here";
    }
    
    # do it for another one:
    my @array2;
    push @array2, "text 2 goes here";
    push @array2, "other text 2 goes here";
    # ...
    

    You can even do this (little bit nasty because of dynamic variables):

    for my $i (1..7) {
        for my $j (1..24) {
             push @{"array$i"}, "text $i, instance $j goes here";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two associative arrays in PHP that are defined as following: $this_week[] =
Ok so I have an array that holds the following elements: $array['a']['b'][0]['c']; $array['a']['b'][1]['c']; $array['a']['d'][0]['c']['c'];
I have the following loop that renders an array a of arrays. Each arrays
I have two numpy arrays that define the x and y axes of a
I have been trying to assign value to an object array that is defined
I have two arrays that I would like to compare and ultimately wind up
I have 2 arrays that I would like to render in a template, one
I have two arrays that I create like this: public int GameBoard[][] = new
I want to have two arrays: supplierList - that contains the int ID of
I'm trying to come up with a way combine two arrays that have different

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.