raygun has asked for the wisdom of the Perl Monks concerning the following question:
$ perl -e 'print "\@hi\n";' @hi
I understand why the backslash before the @ is required here to get a literal @ in an interpolating string: without it, the @ would be interpreted as indicating an array named hi.
It is not needed (though adding it is harmless) in strings where there is no ambiguity about what the @ might represent:
But why is it needed to signal a literal @ in the following?$ perl -e 'print "@=hi\n";' @=hi
$ perl -e 'print "@$0\n";' $ perl -e 'print "\@$0\n";' @-e
How can an @ followed by a $ be interpreted as a valid array name? (The reverse, $@, is a predefined variable, but @$ is not.) And if it can't, why is the backslash needed to indicate this @ is literal?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: escaping the @ in an interpolating string
by Corion (Patriarch) on Aug 10, 2024 at 17:54 UTC | |
by Danny (Chaplain) on Aug 10, 2024 at 18:56 UTC | |
by marto (Cardinal) on Aug 10, 2024 at 19:27 UTC | |
by raygun (Scribe) on Aug 10, 2024 at 18:51 UTC | |
by Danny (Chaplain) on Aug 10, 2024 at 19:11 UTC | |
by raygun (Scribe) on Aug 10, 2024 at 19:23 UTC | |
by NERDVANA (Priest) on Aug 10, 2024 at 19:42 UTC | |
by japhy (Canon) on Aug 13, 2024 at 02:33 UTC | |
by raygun (Scribe) on Aug 13, 2024 at 10:00 UTC |