[b][red]This message was edited by the Firestorm at 2002-7-4 10:32:42[/red][/b][hr]
hi,
I have a 2-dimensional array.
it is called:
@div_alland under it there are arrays with diffrent content called
@div_one[blue]
@div_all[0]
@div_one[1]@div_one...
[/blue]
can I get the number of elements in any of the arrays
@div_onewith the command:
[red]$#div_all[[green]index of the array I want[/green]][/red]
?????????????
Firestorm
fgretz@gmx.de
;-)
Comments
-----------------------
[RED]Heero Yuy
Perl Board Moderator
Perl Semi-Expert[/RED]
what I suggested is of course wrong otherwise I wouldn't disturb you.
the error I get is
syntax error at guest.pl line 74, near "$#div_all["
if I understood you right you said I can -let's say extract- the needed array and then as usually $#array
-yes that could be possible!
sth. like
[code]
#loop as many times as there are arrays in @div_all
for ($j = 0; $j <= $#div_all; $j++)
{
@extract =()
@extract = @div_all[$j]; #so @extract is equal the array div_one at
#the index1
$number = $#extract;
#now I know how many elements I have
for ($i = 0; $i <= $number; $i++)
{
print @div_all[$j][$i];
}
}
[/code]
that must be it!!!!!!
I'l have to try......
good night
Firestorm
fgretz@gmx.de
;-)
: what I suggested is of course wrong otherwise I wouldn't disturb you.
: the error I get is
: syntax error at guest.pl line 74, near "$#div_all["
:
: if I understood you right you said I can -let's say extract- the needed array and then as usually $#array
: -yes that could be possible!
:
: sth. like
: [code]
: #loop as many times as there are arrays in @div_all
: for ($j = 0; $j <= $#div_all; $j++)
: {
: @extract =()
: @extract = @div_all[$j]; #so @extract is equal the array div_one at
: #the index1
: $number = $#extract;
:
: #now I know how many elements I have
: for ($i = 0; $i <= $number; $i++)
: {
: print @div_all[$j][$i];
: }
: }
: [/code]
: that must be it!!!!!!
: I'l have to try......
: good night
: Firestorm
: fgretz@gmx.de
: ;-)
:
:
:
:
That might(emphasis on might) work but it is not what I meant
[code]
$var=$div_all[$j];
$var2 = $$#var;
print $var2;
#or do whatever u wanna do with the value
[/code]
-----------------------
[RED]Heero Yuy
Perl Board Moderator
Perl Semi-Expert[/RED]
[code]
for (my $j = 0; $j <= $#div_all; $j++)
{
for (my $i = 0; $i <= $#{$div_all[$j]}; $i++)
{
print $div_all[$j][$i],"
";
}
}
[/code]
Or doing it without all the index variables:
[code]
my ($row, $elem);
foreach $row (@div_all) {
foreach $elem (@$row) {
print $elem,"
";
}
}
[/code]
austin