LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-15-2011, 09:17 PM   #1
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Rep: Reputation: 15
2D array in perl script


Learning 2D array in perl script. Just wonder how to put array in 2D
Code:
#!/apps/perl/bin/perl

system(clear);
foreach $nn ( 0 .. 4)
{
        foreach $n (0 .. 9)
        {
                $array[$n][$nn] = $n ;
                print(" array is :$array[$n][$nn]\n");
        }
        #push(@array2, "\n");
}
print("\n\nFinal array2 is :\n @array\n");
what i got is
Final array2 is :
ARRAY(0xe76aed0) ARRAY(0xe76af00) ARRAY(0xe76af30) ARRAY(0xe76af60) ARRAY(0xe76af90) ARRAY(0xe76afc0) ARRAY(0xe76aff0) ARRAY(0xe76b020) ARRAY(0xe76b050) ARRAY(0xe76b080)
 
Old 08-15-2011, 09:30 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
That looks a lot like C code. Could you please explain the problem you're trying to solve in Perl? (i.e. "This is the problem, and this is my goal.") As a general (personal) rule, if so much as the idea of two-dimensional arrays pops into my head, I probably need to rethink my approach.
 
Old 08-15-2011, 10:00 PM   #3
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Original Poster
Rep: Reputation: 15
the only programming i learn is C programming. (i am not in software, i need some simple perl script to ease off my work)

The problem is how to aassign multiple arrays & then read the multiple arrays.
My actual script is a bit complicated which need multiple arrays & the arrays is a variable depends on the inputs.
 
Old 08-15-2011, 10:42 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
I suggest that you may wish to explore such questions at http://www.perlmonks.org.

Basically, the Perl language supplies only "one-dimensional" lists and arrays and hashes, but says that any of those elements could be "a reference to" anything-at-all. So, your "two-dimensional" (or "n"-dimensional) data structure is built up out of a list or array, in which each element consists of "a reference to" another such list or array, ad infinitum.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing array from one perl script to another prasannarathi Programming 2 12-14-2010 08:02 PM
[SOLVED] shell script help: copying directory list into an array and then accessing the array richman1234 Linux - Newbie 6 07-25-2010 11:19 PM
storing values in an array in perl script :) kdelover Programming 5 09-16-2009 06:01 PM
[perl] copying an array element into another array s0l1dsnak3123 Programming 2 05-17-2008 01:47 AM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration