nitin.sh1982 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have a question related to the following code pasted below.
sub new { my ($class, $options) = @_; if (!ref $options) { shift @_; $options = scalar @_ ? {@_} : {}; } #Some Code bless $self, $class; #Some Code return $self; }
I am confused what the line
$options = scalar @_ ? {@_} : {};does in this code. What happens to $options after it is executed?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Creating 'new' subroutine.
by jwkrahn (Abbot) on Oct 11, 2013 at 06:30 UTC | |
by nitin.sh1982 (Initiate) on Oct 17, 2013 at 04:21 UTC | |
by jwkrahn (Abbot) on Oct 17, 2013 at 04:56 UTC | |
Re: Creating 'new' subroutine.
by Anonymous Monk on Oct 11, 2013 at 07:04 UTC | |
by LanX (Saint) on Oct 11, 2013 at 10:21 UTC | |
by tobyink (Canon) on Oct 11, 2013 at 12:04 UTC | |
by Anonymous Monk on Oct 11, 2013 at 20:35 UTC | |
by boftx (Deacon) on Oct 12, 2013 at 00:52 UTC | |
by Lennotoecom (Pilgrim) on Oct 11, 2013 at 10:03 UTC | |
by Anonymous Monk on Oct 11, 2013 at 11:00 UTC | |
by Lennotoecom (Pilgrim) on Oct 11, 2013 at 11:15 UTC | |
by Anonymous Monk on Oct 11, 2013 at 11:17 UTC | |
| |
by nitin.sh1982 (Initiate) on Oct 17, 2013 at 04:27 UTC |
Back to
Seekers of Perl Wisdom