rbi has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
could somebody explain me why || and or have a different behaviour as in the example below ?
Thank you very much.
use strict; use warnings; use Data::Dumper; my @array = (1,2,3,4); my @index = (1,3); &these(Index=>\@index); &those(Index=>\@index); sub these { my %args = @_; my @index = @{$args{Index}} || (); my $dump = Dumper($args{Index}); print "$dump"; $dump = Dumper(\@index); print "$dump"; } sub those { my %args = @_; my @index = @{$args{Index}} or (); my $dump = Dumper($args{Index}); print "$dump"; $dump = Dumper(\@index); print "$dump"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Setting defaults in subroutines
by davorg (Chancellor) on Aug 04, 2004 at 09:43 UTC | |
by rbi (Monk) on Aug 04, 2004 at 09:54 UTC | |
by PerlingTheUK (Hermit) on Aug 04, 2004 at 10:23 UTC | |
Re: Setting defaults in subroutines
by PodMaster (Abbot) on Aug 04, 2004 at 09:45 UTC | |
Re: Setting defaults in subroutines
by hv (Prior) on Aug 04, 2004 at 11:02 UTC | |
by hmerrill (Friar) on Aug 04, 2004 at 11:26 UTC | |
Re: Setting defaults in subroutines
by Fletch (Bishop) on Aug 04, 2004 at 13:02 UTC |
Back to
Seekers of Perl Wisdom