in reply to Simple Subroutine Question
If you disregard said advice, you could do it as follows:
Alternately you could make the two forms besub ssh_connect { my ($self, $user, $pass) = @_; if (3 < @_) { (undef, my %args) = @_; $user = $args{user} or confess("No user"); $pass = $args{pass} or confess("No pass"); } print "$user and $pass\n"; }
and dispatch on whether there are fewer than 3 arguments. This is actually a saner way to go, but it does require {}.$foo->ssh_connect($user, $password); $foo->ssh_connect({user => $user, pass => $password});
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Subroutine Question
by walkingthecow (Friar) on Aug 01, 2009 at 01:00 UTC | |
by tilly (Archbishop) on Aug 01, 2009 at 01:13 UTC |