Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert scalar to an array

Status
Not open for further replies.

NateBro

Programmer
Sep 1, 2004
233
US
ok, i tried looking for a post on here and came up with nothing.

what i'm trying to do is make an array inside of an array.

basicly the same as this...

Code:
  $array = [
               [1, 2, 3, 4] ,
               [1, 2, 3, 4]
            ]

but i need to do it some thing like...

Code:
  $array[1] = @array;

i have no idea how many entries will be inside of each sub array so ya, i'm lost, i know how to retrive them, but just not how to add them :(

thanks for any help you can give!
:D
~Nate_Bro
 
I think the following code is what you're looking for:
Code:
my @AoA;
while (<DATA>) {
    my @temp = split;
    push @AoA, [@temp];
}

__DATA__
a b c d
e f g h
i j k l
For more information, look at perldoc perldsc - specifically anything on Arrays of Arrays.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top