Hi all,

I'm hoping to get some ideas on how to write my subs, specifically on passing variables into them and how best to do it.

Currently I do this:


example_sub ( $some_scalar, $some_hash_ref, 'some string' );

sub example_sub {
        my ( $passed_scalar, $passed_hash_ref, $passed_string ) = @_;
        
        
}


This is fine, except when I want to pass in something else at a later date, when I find I need the sub to do something extra, I have to go back and update all of the calls to the sub that I wrote before.

So if I wanted to add $some_array_ref...


# A call to the sub that doesn't need to use the array_ref
example_sub ( $some_scalar, $some_hash_ref, [], 'some string' );

sub example_sub {
my ( $passed_scalar, $passed_hash_ref, $some_array_ref, $passed_string ) = @_;
        
        
}


I have to go back to all of the other calls to the sub and add an empty array ref in the call.

I realise I could stick them on the end of the list to avoid doing this, but I like them to be in a logical order. Any better suggestions?

I thought about using a hash instead of a list of variables.


example_sub (
        {
                some_scalar => $some_scalar,
                some_hash_ref => $some_hash_ref,
                some_string => 'some string',
        }
);

So I could add to it any way I wanted and write them in any order.

Any better suggestions?

Thanks in advance,
Nigel


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to