Jakob Lell <[EMAIL PROTECTED]> wrote: : : you can use prototypes to pass array references. : see perldoc perlsub for more details. : : sub showIt([EMAIL PROTECTED]@); : my @alpha=("a","b","c"); : my @numer=(1,2,3); : showIt(@alpha,@numer); : sub showIt([EMAIL PROTECTED]@) : { : my($a,$b) = @_; : print "a[0]:" . $$a[0] . "\n"; #accessing by reference : print "b[0]:" . $$b[0] . "\n"; : }
I also felt prototyping was a superior method to handle subroutine calls. But I found it has some limitations. About this same time I adopted the philosophy that, except in rare cases, subroutines should not change their input data. Here's an example ($w, $x, $y, and $z are references to arrays): Here I choose to change the values in $x and $y: my( $x, $y ) = some_sub( $x, $y ); In this case I choose to preserve the values in $x and $y: my( $w, $z ) = some_sub( $x, $y ); One advantage to this preservation of input data is that I can use data that is read-only. Like a list: my( $w, $z ) = some_sub( $x, some_other_sub( $y ) ); This leads to another style rule. When returning a list or an array, return references. If I use prototypes I'll need to wrap subroutine returns in @{}: my( $w, $z ) = proto_sub( @x, @{ other_proto_sub( @x, @y, ) } ); @{} looks messy and it converts one sub's output to an array just to put it back into a reference that we had in the first place. So, to increase readability and consistency I decided to avoid using prototypes. Just my $.03 (I'm a big spender), Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]