in reply to Pass an optional parameter to a subroutine
This is exactly the kind of problem that the forthcoming "defined or" (//) operator is designed to deal with. If you're using the current development version of Perl (5.9) or when the next stable version (5.10) is released, you'll be able to write
my $db_write = shift // 1;
Instead of
my $db_write = shift; $db_write = 1 unless defined $db_write;
Actually, I think that currently I'd write your code like this
my $ref_mail = shift; my $db_write = @_ ? shift : 1;
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pass an optional parameter to a subroutine
by ysth (Canon) on Sep 15, 2006 at 08:36 UTC | |
|
Re^2: Pass an optional parameter to a subroutine
by Tanktalus (Canon) on Sep 15, 2006 at 15:54 UTC | |
|
Re^2: Pass an optional parameter to a subroutine
by radiantmatrix (Parson) on Sep 15, 2006 at 17:47 UTC | |
by Velaki (Chaplain) on Sep 15, 2006 at 17:54 UTC |