On 2018-11-22 8:08 a.m., David Precious wrote:
You'll often see these operators used to provide default values.
e.g.
sub hello {
my $name = shift;
$name ||= 'Anonymous Person';
Which is usually written as:
sub hello {
my $name = shift || 'Anonymous Person';
I do notice that there isn't actually a very useful section on ||=
and //= - I may try to raise a pull requests to add more documentation
on them.
$var ||= 'VALUE';
Is just shorthand for:
$var = $var || 'VALUE';
The syntax is borrowed from the C programming language and it is
slightly more efficient when compiled to machine code.
John
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/