On Sat, Sep 30, 2017 at 10:30 PM, ToddAndMargo <[email protected]>
wrote:
> On 09/30/2017 02:15 PM, Brandon Allbery wrote:
>
>> Basically: < > is single quotes and treats variables and expressions as
>> literals. << >> is double quotes and interpolates variables but not general
>> expressions. And { } does no quoting at all and uses general expressions.
>
>
This gets a little complex...
> 1) expressions
>
> 2) the difference between "expressions" and "general expressions"
>
Doublequoted strings don't just expand variables. Postfixes (like [] or <>
to look up values in arrays/hashes) are also understood; method calls on
variables also work, as long as they end with a parenthesized expression
(so, "hi $foo.name" will not work (it'll expand '$foo' instead of '$foo.name')
but "hi $foo.name()" will, provided $foo contains an object with a 'name'
method). This is what I meant by 'expression', which I should have probably
called 'simple expression' or something.
> 3) Quoting. The difference between "" and <>
>
' ' strings and <> postfixes are almost identical. %foo<a> is the same as
%foo{'a'}. But %foo<a b> acts like you did: %foo{'a'}, %foo{'b'}
" " strings and << >> postfixes are almost identical. %foo<<a>> is the same
as %foo{"a"}. But %foo<<a b>> acts like you did: %foo{"a"}, %foo{"b"}
Inside ' ' strings, everything is literal.
Inside " " strings, variables like $foo and (simple) expressions (described
above) will be replaced by their values; and you can use { } to insert the
result of any expression. (This also works in << >>.)
pyanfar Z$ 6 'my %x = ("a"=>"b","c"=>"d", "e"=>"f"); my $v = "b"; say
%x<<a {$v.succ}>>'
(b d)
4) "interpolating" as it refers to Perl (not math, where you "guess"
> what a value is based on values on both sides of you).
>
Replacing something inside a string with the string representation of its
value. This sense is also used in documentation for the shell, where you
can also interpolate `` subcommand output and such.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net