in reply to Re^3: Passing argument by reference (for a scalar)
in thread Passing argument by reference (for a scalar)

Same thing would happen if you did my $STRING = ${ +shift }; if you had passed a reference. If you don't want a copy, don't make a copy! (Also, don't use a 20 year old version of the language!) This was already all covered in detail. Including how what you claim happens hasn't been true for 10 years.

Replies are listed 'Best First'.
Re^5: Passing argument by reference (for a scalar)
by Danny (Chaplain) on Sep 10, 2024 at 14:53 UTC
    I'm not familiar with ${ +shift }; syntax. It looks like the + is a way to interpret 'shift' as a command inside ${}. I'm not readily finding documentation for this. Where should I look?
        Thanks!
      > I'm not familiar with

      That's why I prefer

      ${ shift() }

      even if it needs one letter more.

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

      + is the unary-+ operator. It does absolutely nothing but evaluate to the same thing its operand does. It even provides the same context as the one in which it's evaluated.

      +5 # Same as `5` +"abc" # Same as `"abc"` +@a # Same as `@a`, in both scalar and list context

      ${ shift } is just a weird undocumented way of writing $shift. I didn't want that. I wanted to use the shift operator. ${ +shift } can't be parsed as a scalar named +shift, so it has the desired effect.

        A truly useful use of + is for constructing hashes with map:
        my %hash = map +($_=>undef), @list;
        Without the +, Perl would think you wanted to call map with 2 args, not over @list.