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};

— Ken


In reply to Re: POD for use feature 'declared_refs' wrong by kcott
in thread POD for use feature 'declared_refs' wrong by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.