u are trying to creat amulti dimentional array i guss but perl does not have
multi dymenctional arrays u will have to use referances (read perldoc
perlref)




here is an simpal exampal


my @table;

for ($c=1;$c<11;$c++){

my @ta;
$table[++$#table] = \@ta;  #***************  type "perldoc prelref"  in your
commant line for more help on this
}

for ($c1=1;$c1<11;$c1++){
for ($c2=1;$c2<11;$c2++){

$table[$c1]->[$c2]=$c1*$c2;
}
}


for ($c1=1;$c1<11;$c1++){

print "Multiplication Table of $c1\n\n\n";
for ($c2=1;$c2<11;$c2++){

print "$c1 x $c2 = $table[$c1]->[$c2]\n";
}

print "\n\n________________________________________\n\n";

}






----- Original Message -----
From: "Gajo Csaba" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 31, 2002 9:29 PM
Subject: A very, very simple question


>
> Hi,
> I've started learning Perl a few days ago, but I'm a
> computer science student, so I'm not a complete idiot
> :)
>
> This is the problem: I'm trying to make a simple 2D
> matrix that represents the product of the numbers 1-10
> (don't know how to tell it in English, it's that table
> that kids learn when their 2nd grade)
>
> I've wrote the following:
>
> sub init
> {
>  for ($a=0;$a<10;$a++)
>  {
>   $table[$a,0] = $a;
>   $table[0,$a] = $a;
>  }
> }
>
> sub count
> {
>  for ($a=0;$a<10;$a++)
>  {
>   for ($b=0;$b<10;$b++)
>   {
>    $table[$a,$b] = $table[$a,0] * $table[0,$b];
>   }
>  }
> }
>
> sub print
> {
>  etc...
> }
>
> init;
> count;
> print;
>
> -----------
>
> The count function might not have been written this
> way, but the init function sure looks like that, and
> that is the function I'm having a problem with. It
> doesn't work, but can't figure out why? It should give
> a result like this:
> 0123456789
> 1000000000
> 2000000000
> 3000000000
> 4000000000
> 5000000000
> 6000000000
> 7000000000
> 8000000000
> 9000000000
>
> But instead I get
> 9999999999
> 9000000000
> 9000000000
> 9000000000 ... etc
>
> So I wrote a procedure like this:
>
> sub test
> {
>  for ($a=0;$a<10;$a++)
>  {
>   print $a;
>   $table[$a,0] = $a;
>  }
> }
>
> .... and when I print the table, I get the following:
> 123456789  (from the print $a line) 999999999
> 99999999
> 99999999
> 99999999
> .... etc...
>
> It's like it counts to 9, and then fills the table
> with nines. But why?
>
> Anyway, can someone help?
>
> Thanks, Csaba
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to