Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: Simple perl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 10962 of 11520
Post > Topic >>

Re: Simple perl array question

by rich.japh@[EMAIL PROTECTED] (Richard Lee) Apr 20, 2008 at 06:06 PM

dfairman16@[EMAIL PROTECTED]
 wrote:
> Well simple if you are not learning Perl. You guessed it, I am a
> newbie.
>
> My question is if I have an array like this, actually it is my whole
> program.
>
> my @[EMAIL PROTECTED]
( [5, [1,3,18,21]], [16, [1,2,3]], [21, [1]]);
> print #@[EMAIL PROTECTED]
> print #@[EMAIL PROTECTED]
> print #@[EMAIL PROTECTED]
>
> What I had expected and what I want is to print out 4, 3, and 1 but it
> prints out 1 and 1 and I don't know why. The 4,3, and 1 are the
> lengths of the second array in the array of arrays.
>
>
> If someone could put me right I can move on (to the next problem and
> understanding your code).
> Thank you
> David
>
>
>   
I am not sure if this is what you want, but try this,

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my @[EMAIL PROTECTED]
( [5, [1,3,18,21]], [16, [1,2,3]], [21, [1]]);

print Dumper(@[EMAIL PROTECTED]
);

print "$testarray[0][0]\n";   #first number which is 5
print "$testarray[0][1][0]\n";#first number which is 1
print "@[EMAIL PROTECTED]
";#prints entire first VAR, which is 5 , 1, 
3 , 18 , 21
[root@[EMAIL PROTECTED]
 tmp]# ./!$
.././././././././././././././././././somebody.pl
$VAR1 = [
          5,
          [
            1,
            3,
            18,
            21
          ]
        ];
$VAR2 = [
          16,
          [
            1,
            2,
            3
          ]
        ];
$VAR3 = [
          21,
          [
            1
          ]
        ];
5
1
1 3 18 21
 




 3 Posts in Topic:
Simple perl array question
dfairman16@[EMAIL PROTECT  2008-04-20 12:05:42 
Re: Simple perl array question
rich.japh@[EMAIL PROTECTE  2008-04-20 18:06:45 
Re: Simple perl array question
krahnj@[EMAIL PROTECTED]   2008-04-20 15:20:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 13:13:46 CDT 2008.