G'day Rolf,
"this POD is either confusing or plain wrong"
I'd say a bit of both.
In the context of the first paragraph of
"Declaring a Reference to a Variable",
experimental::refaliasing should definitely be replaced with experimental::declared_refs.
That section goes on to say, "It is intended mainly for use in assignments to references ...".
It would be appropriate to mention experimental::refaliasing at this point.
"NB: that use feature qw(declared_refs) doesn't seem to make sense without the other feature."
There are instances where you want a declaration without assignment (not in "void" context).
I've certainly used "\my VAR" in this context often enough.
This doesn't require any special feature or warnings code.
$ perl -E '
use strict;
use warnings;
say ref \my $scalar;
say ref \my @array;
'
SCALAR
ARRAY
Off the top of my head, I couldn't think of an application for "my \VAR" in this context;
however, just for completeness, here's a contrived example showing that "declared_refs" is required
but "refaliasing" is not.
$ perl -E '
use strict;
use warnings;
say ref my \$scalar;
say ref my \@array;
'
The experimental declared_refs feature is not enabled at -e line 4.
$ perl -E '
use strict;
use warnings;
use feature "declared_refs";
say ref my \$scalar;
say ref my \@array;
'
Declaring references is experimental at -e line 5.
Declaring references is experimental at -e line 6.
SCALAR
ARRAY
$ perl -E '
use strict;
use warnings;
use feature "declared_refs";
no warnings "experimental::declared_refs";
say ref my \$scalar;
say ref my \@array;
'
SCALAR
ARRAY
While these features remain experimental, they're rather unwieldy
[see Update below]
and probably easy to get wrong:
$ perl -E '
use strict;
use warnings;
use feature qw{refaliasing declared_refs};
no warnings qw{experimental::refaliasing experimental::declared_re
+fs};
my ($sc, @ar) = qw{qwert asdfg zxcvb};
my \$scalar = \$sc;
my \@array = \@ar;
say $scalar;
say "@array";
'
qwert
asdfg zxcvb
[Note:
Perl 5.34 used for all examples.]
Update:
Regarding my comment about experimental features being unwieldy; they are, in fact, not as unwieldy as I presented.
I had forgotten about the experimental pragma
(thanks to ++ikegami for the reminder).
The two lines:
use feature qw{refaliasing declared_refs};
no warnings qw{experimental::refaliasing experimental::declared_re
+fs};
can be reduced to the much simpler one line:
use experimental qw{refaliasing declared_refs};
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.