in reply to Re: escaping the @ in an interpolating string
in thread escaping the @ in an interpolating string

I guess I should have been less specific!
@$0 is seen as @{ $0 }
The issue isn't limited to $0 following the @: no matter what variable follows it—whether it exists or not—the @ is not interpreted literally.
$ perl -e 'print "@$$\n";' $ perl -e 'print "@$undefined_variable\n";' $ perl -e 'print "@$]\n";' ] $ perl -e 'print "@$(\n";' (
Interestingly, sometimes the entire @$foo seems to be interpreted as a unit, printing nothing, and other times @$ seems to be interpreted as one unit, printing whatever follows it literally. In no case is the @ interpreted literally. And, of course, in all cases preceding the @ with a backslash solves that, and allows the following variable to be interpolated:
$ perl -e 'print "\@$$\n";' @24477 $ perl -e 'print "\@$undefined_variable\n";' @ $ perl -e 'print "\@$]\n";' @5.030003 $ perl -e 'print "\@$(\n";' @500 7 10 11 16 18 19 27 35 80 85 100 105 500

Replies are listed 'Best First'.
Re^3: escaping the @ in an interpolating string
by Danny (Chaplain) on Aug 10, 2024 at 19:11 UTC
    Those are all doing the same thing that Corion explained. They are inferring that $$, $undefined_variable etc are symbolic references to an array. If you 'use strict' it will give an error. Without 'use strict' you can do something like:
    perl -e '@hi = (1,2,3), my $x = "hi"; print "@$x\n";'
    and it will output:
    1 2 3
      Ah, it would've helped if I hadn't misread Corion's explanation. Yours managed to penetrate my thick skull. Thank you!
Re^3: escaping the @ in an interpolating string
by NERDVANA (Priest) on Aug 10, 2024 at 19:42 UTC
    More to the point, @$foo is perfectly useful syntax even with strict enabled:
    use strict; use warnings; my $foo= [ 1, 2, 3 ]; for (@$foo) { say $_ }
Re^3: escaping the @ in an interpolating string
by japhy (Canon) on Aug 13, 2024 at 02:33 UTC
    In the case of those punctuation variables (e.g. $] and $(), Perl interprets "@$]" as "@$" and "]", and since @$ is empty, you get nothing, followed by the punctuation character.
    Jeffrey Pinyan (TypeScript, JavaScript, PHP, Perl; in that order nowadays)
    @JeffPinyan@NightSkyJeff
    Melius servire volo
      Yeah, I could deduce from the output that it was doing that, but initially I couldn't figure out why it would parse those two differently from the others. But with the light shed by Corion and Danny, I figured it out: $] and $( expand into things that aren't legal variable names. So perl must, upon noticing that, deduce that a symbolic reference is not what it's seeing, and fall back on the alternate parsing you mention.