This could be it. My final question is how to do it when we have two
arrays to pass to a subroutine. I am using the techniques I came
accross in perldoc perlsub but could not figure out what should I have
on the marked line.
sub func2 {
my ($local_value, $local_array) = @_;
foreach my $value (@$local_value) {
print "$value \n";
}
for my $i (0 .. @$local_array - 1) {
for my $j (0 .. @{$local_array[$i]} - 1) { <= line
print "@$local_array[$i][$j] "; <= line
}
print "\n";
}
}
my @myarray=([1,2,3,4,5],[6,7,8,9,10],[11,12,12,3,4]);
my @value=(A,B,C,D,E);
func2 ([EMAIL PROTECTED], [EMAIL PROTECTED]);
The above codes would only return the content of array @value.
On Thu, 28 Oct 2004 20:14:14 -0700, John W. Krahn <[EMAIL PROTECTED]> wrote:
> Khairul Azmi wrote:
> > 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?
>
> The problem is that Perl's subroutines pass all their arguments as a single
> list so in your case @local_array gets everything and $local_value gets
> nothing. You can reverse the order of the arguments or use a reference for
> the array.
>
> perldoc perlsub
>
>
>
>
> 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>