Thanks for the solution. Not sure if this is still on topic but I then
add an additional parameter to the subroutine
sib func {
my (@local_array, $local_value) = @_;
print "$local_value \n";
for my $array ( @local_array ) {
for my $element ( @$array ) {
print "$element ";
}
print "\n";
}
}
my $value = 5;
my @myarray = ( [ 1,2,3,4,5 ], [ 6,7,8,9,10 ] );
func( @myarray, $value );
But then the for loop would return one extra empty line. Does it has
to do with the additional parameter? What if the parameter is another
array? Another 2D array may be?
Azmi
On Thu, 28 Oct 2004 02:52:04 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:
> Khairul Azmi wrote:
> > I've been trying to solve this problem using many techniques I found
> > on the websites but still unsuccessfully
> >
> > sub func {
> > my (@local_array) = @_;
> >
> > for (my $i=0;$i<@local_array;$i++) {
> > for (my $j=0;$j<@local_array[$i];$j++) {
> > print "$local_array[$i[[$j] ";
> > }
> > print "\n";
> > }
> >
> > $myarray[0]=(1,2,3,4,5);
> > $myarray[1]=(6,7,8,9,10);
>
> You are only assigning a single value to a scalar. This does the same as above:
>
> $myarray[0]=5;
> $myarray[1]=10;
>
> > func (@myarray);
>
> You want something like this:
>
> sub func {
> my @local_array = @_;
>
> for my $array ( @local_array ) {
> for my $element ( @$array ) {
> print "$element ";
> }
> print "\n";
> }
> }
>
> my @myarray = ( [ 1,2,3,4,5 ], [ 6,7,8,9,10 ] );
>
> func( @myarray );
>
> John
> --
> use Perl;
> program
> fulfillment
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>