develooper Front page | perl.perl6.users | Postings from June 2022

Re: Easier way to load a buffer?

Thread Previous
Elizabeth Mattijsen
June 10, 2022 21:00
Re: Easier way to load a buffer?
Message ID:

> On 10 Jun 2022, at 22:47, ToddAndMargo via perl6-users <> wrote:
>>> On Fri, 10 Jun 2022 at 15:49, ToddAndMargo via perl6-users < <>> wrote:
>>>    Hi All,
>>>    I am looking for an easier way to load a buffer.
>>>    I know about this way
>>>    [4] > my Buf $, 0x54, 0xFF, 0x53);
>>>    Buf:0x<2A 54 FF 53>
>>>    I would like to do it on one big blast:
>>>    my Buf $;
>>>    Cannot unbox 170 bit wide bigint into native integer
>>>    But do not know the proper syntax.
>>>    Any words of wisdom?  Am I stuck with the hard way?
>>>    Many thanks,
>>>    -T
> On 6/10/22 08:36, Simon Proctor wrote:
>> So Buf is expecting a list of integers. If' you've got one long one in a string like "2A54FF53A5F1D36F1CEA7E61FC37A20D54A77FE7B78" you want to split it into smaller values so something like this?
>> my $hex = "2A54FF53A5F1D36F1CEA7E61FC37A20D54A77FE7B78";
>> my Buf $ *.parse-base(16) ));
>> Which does the trick I think.
> What does the * i *.parse-base do?

*.parse-base(16) is an example of a WhateverCode object.

It is basically syntactic sugar for easy creation of Callable blocks.  In this case,
it created  -> $_ { .parse-base(16) }

The * is interpreted in the Raku Grammar as a sign to create a WhateverCode object: it basically
represents the $_ in the signature of the created Block, and of course the $_ inside that block.:
Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About