On Thu, 22 Nov 2018 12:33:25 -0800
"John W. Krahn" <[email protected]> wrote:
> 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';
Sure - but that doesn't provide a simple, useful example of ||= which
the OP was asking about.
> > 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.
Indeed - *I* know that, but it strikes me that it could be better
documented, to make it easier for people new to Perl to find the
documentation. I went to perldoc perlop expecting to be able to find a
section to point the OP at as a "here's the documentation for it", and
couldn't find anything particularly useful.
That strikes me as sub-optimal :)
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/