There are a slew of problems in this sample. For a start I strongly recommend that you add use strict; use warnings; to all the Perl scripts you write or maintain!

Your immediate problem is solved by using an array of arrays. The syntax changes from @store_get_dist1 to @{$store_get_dist[1]}.

Now for the real issues:

The following may be a little closer to what you require (untested):

use strict; use warnings; my @all_stores; my @store_get_dist; my $dbv; my $count = 0; my $test_num = 1; # Finds district for all stores foreach my $dist_fld (@all_stores) { $test_num++ if ++$count =~ /(\d*)998/; my $new = $dist_fld.","; print "$new\n"; push(@{$store_get_dist[$test_num]},$new); } print "Number of queries needed: $test_num\n"; for my $i (1 .. $test_num) { my $last_one = pop @{$store_get_dist[$i]}; #error occurs here chop($last_one); push (@{$store_get_dist[$i]}, $last_one); #error occurs here # GRAB ALL STORE, DISTRICT, REGION AND GROUP info my $get_district = "SELECT distinct(DIST_I)\n". "FROM BCE_STORE\n". "WHERE LOC_I in (@store_get_dist${i})"; my $grab_dist = $dbv->prepare("$get_district"); ### Execute the statement in the database $grab_dist->execute; print "$get_district\n"; while ( my $row = $grab_dist->fetchrow( ) ) { print "$row\n"; } }

Update opps, @{$store_get_dist[1]} -> @{$store_get_dist[$test_num]}


DWIM is Perl's answer to Gödel

In reply to Re: adding number to array name by GrandFather
in thread adding number to array name by Anonymous Monk

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.