http://qs321.pair.com?node_id=11120443


in reply to Re^3: Shouldn't references be readonly? (updated)
in thread Shouldn't LITERAL references be readonly? (updated)

Ok, I'd like to contradict myself.

I'd actually be ok with making "unassigned" scalars read-only. That includes [...], $x.$y, <>, etc.

It might have performance implications, but they should be extremely tiny.

It would break some code (such as my @lines = map { chomp; } <>;), but I think the benefits might be larger.

Replies are listed 'Best First'.
Re^5: Shouldn't references be readonly? (updated)
by LanX (Saint) on Aug 07, 2020 at 10:34 UTC
    > It would break some code

    I think if it comes to simple scalar types like strings this would result in a migration nightmare.

    Hence I wouldn't include the cases like $x.$y, <>, etc at least by default.

    Refs on the other hand should be immutable, because the result is always junk.

    But I doubt we have the resources to implement that anyway.

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

      @a = map { $_ = 3; } [];

      is no more or less junk than

      @a = map { $_ = 3; } $x.$y;

      Are you therefore talking about [] + 1? Making the reference read-only is not going to catch that.

        There are far more situations where it might make sense to append or add something to a simple type.

        Not so with refs, no way a .= or a += will lead to anything meaningful.

        Well except when blessed and overloaded. But that's far fetched.

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