Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: POD for use feature 'declared_refs' wrong

by LanX (Sage)
on Oct 17, 2021 at 20:24 UTC ( #11137659=note: print w/replies, xml ) Need Help??


in reply to Re: POD for use feature 'declared_refs' wrong
in thread POD for use feature 'declared_refs' wrong

Thanks Ken,

you are right, it's possible to use my $var; in non-void context, actually I'm regularly prepending warn for debugging.°

> While these features remain experimental, they're rather unwieldy and probably easy to get wrong:

They are indeed not nice to activate, I'd probably write a module bundling those four steps to avoid boilerplate.

But the feature is very nice in many circumstances, Brian d Foy² lists some here:

it's also very handy when working with aliases, and one doesn't want to litter ones code with cryptic $_[N°]

D:\tmp\pm>perl -Mfeature=:all -M-warnings sub uc_name { my \$name = \$_[0]; $name = uc $name } $n="ken"; uc_name($n); say $n __END__ KEN

FWIW Perl4 had an aliasing feature with *type-globs, but this was restricted to package vars.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) actually I'm even putting the warn into the line before, like this I'm flexible with (un)commenting it.

# warn my $x = ...;

²) corrected spelling twice (= deux fois ;)

Replies are listed 'Best First'.
Re^3: POD for use feature 'declared_refs' wrong
by kcott (Bishop) on Oct 18, 2021 at 17:55 UTC
    "FWIW Perl4 had an aliasing feature ..."

    Purely as an historical note, I do recall reading about that in the first Camel book. In perlhist:

    Perl 4 introduced the first Camel book.  Really.  We mostly just
        switched version numbers so the book could refer to 4.000.
    

    So that feature would have existed in Perl3. I don't have any information on which specific Perl version introduced it. I don't believe I used that feature in any version prior to Perl5.

    — Ken

      I'm pretty sure one needed to pass a glob for multiple arrays, because references were missing

        foo(*arr1,*arr2)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        A trip down memory lane ...

        I reached across my desk and grabbed my original (pink) version of the Camel book. After blowing off a decade or two's worth of dust, I had a look around.

        [Note: The printing history shows Jan. 1991 as "First Edition", then Aug. 1991 and Mar. 1992 as "Minor corrections". It would be a fair assumption that I have the more recent of those; page numbers below may be out by one or two for those with other versions.]

        In "Chapter 3 The Gory Details" (pp. 65-121); under the "Packages" section (pp.119-121); I found on page 120:

        local(*foo) = *bar; local($_main{'foo'}) = $_main{'bar'};

        ... the *foo is more efficient because it does the symbol table lookup once at compile time ...

        Also of nostalgic interest was the use of $main'var instead of $main::var. I haven't used the former version in over 20 years; however, it's still valid:

        $ cat pm_11137628_pkg_sep.pl use strict; use warnings; our $x = 42; print $], "\n"; print $main'x, "\n"; print $main::x, "\n";
        $ perl pm_11137628_pkg_sep.pl 5.034000 42 42
        "foo(*arr1,*arr2)"

        Under the "Subroutines" section (pp. 99-102); on page 99; I note a small syntax change is required:

        "A subroutine is called using the do operator or the & operator. The & operator is the preferred form."

        However, other than that small syntax change, the gist of what you wrote is correct. There's an example on page 102:

        sub arrayadd { local(*a, *b) = @_; ... } @foo = (1,2,3); @bar = (10,20,30); @totals = &arrayadd(*foo, *bar);

        [Disclaimer: Everything I've quoted from the book needed to be entered by hand. I believe it's all correct but apologise in advance for any typos that may have crept in.]

        The "trip down memory lane" concludes. I hope that was an interesting read. I do acknowledge that it was way off-topic with respect to the OP subject.

        — Ken

Re^3: POD for use feature 'declared_refs' wrong
by ikegami (Patriarch) on Oct 18, 2021 at 13:33 UTC

    They are indeed not nice to activate, I'd probably write a module bundling those four steps to avoid boilerplate.

    Which four steps? Enabling the two features and disabling the two warnings? It already exists.

    use experimental qw( refaliasing declared_refs );

      ++ Thanks for the reminder about the experimental pragma. I've added an update to my post.

      — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137659]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2022-01-19 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?