On Sun, Oct 1, 2017 at 4:01 AM, ToddAndMargo <toddandma...@zoho.com> wrote:

> On 09/30/2017 07:59 PM, Brandon Allbery wrote:
>
>> 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)
>>
> What does the ".succ" do?
>

In this case it's just an example of an expression that wouldn't have
worked by normal interpolation (although $v.succ() would have, as I
described earlier).

succ is short for "successor"; think of it as the generalized version of
adding 1 to something. In Perl 6, it can be used (but ideally shouldn't) on
numbers, or to get the next element of an Enum (note that this might not
necessarily correspond to its numeric value plus one), or as in this case
to get the next notional "value" of a string: this is a somewhat
rationalized version of Perl 5's "magic autoincrement" and is described at
https://docs.perl6.org/type/Str#method_succ . It's useful, especially in
the form of the ++ autoincrement operator, for autogenerating filenames.

    pyanfar Z$ 6 'my $x = "file1.txt"; say $x.succ'
    file2.txt

-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

Reply via email to