in reply to Re: Implicit references? module -> feature -> pragma -> "Perl8" ?
in thread Implicit references? module -> feature -> pragma -> "Perl8" ?

I'm meditating about both. The general idea is to have an automatic duality of ref-types

You know the implementation side better than me, that's why I proposed different implementations/semantics.

The first version is a naive (but easy) implementation with the pitfall that both variables could later diverge.

To catch this a naive implementation would either need to make the ref $a readonly or use a tie to update \@a (here are dragons)

(I "think" a POC for testing could be implemented with Keyword::Simple)

The second version would be ideal, because diverging is ruled out. But I'm not sure if it's even possible to implement this in a performant way and what the repercussions would be.

An alternative syntax could be

mine $a = [1,2,3];

Of course all of this requires testing many use cases with POCs before going live.

FWIW:
Regarding the new keywords, in the long run I'd rather prefer a pragma changing my and our and signatures to act this way.

Legacy code would continue working and new code become much easier.

I doubt many people reuse the same symbol name in different sigil/types.

Style guides require arrays and hashes to have self describing names, so it would be obvious that $dictionary is the reference of %dictionary .

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

Replies are listed 'Best First'.
Re^3: Implicit references? module -> feature -> pragma -> "Perl8" ?
by Anonymous Monk on May 12, 2026 at 21:04 UTC
    I doubt many people reuse the same symbol name in different sigil/types.

    I do this all the time because if I have an array of @stuff and a hash of the same %stuff I think they should both be called stuff. If I need a variable about stuff I'll call that $stuff too.

    it's considered bad style to reuse the same symbol for different types

    Considered by who?

    if we want to pass an @arr to a function we need to explicitly reference it \@arr and inside the function we always need to explicitly dereference it.

    We don't need to do that at all, unless @INC is huge:

    perl -le 'sub INC { print for @_ } INC(@INC)'
      > Considered by who?

      Various style guides, most prominently Perl Best Practices comes to mind where IIRC arrays need to have plural names, while scalars are singular.

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

        for my $sheep (@sheep) { $sheep->say ('Baa!') };

        Which rule wins here?


        🦛

      if we want to pass an @arr to a function we need to explicitly reference it \@arr and inside the function we always need to explicitly dereference it.

      Correct and sorry I misunderstood...