Posts

Showing posts with the label perl6

Does Baggy add (+) work on MixHash weights?

Image
Clash Royale CLAN TAG #URR8PPP Does Baggy add (+) work on MixHash weights? I am using a MixHash to combine two Hashes with the Bag add (+) operator. This seems to work - but ... I am a bit surprised that the result of the union needs to be re-coerced back to a MixHash. My guess is that the Bag add (+) infix operator coerces everything to a Bag first and returns the result as a Bag. This may be risky for me as some of my weights are negative (thus the Mix in the first place). Will this properly add negative weights? Alternatively, is there a Mix add (+) operator? my MixHash $dim-mix; for ... { my $add-mix = $!dims.MixHash; $dim-mix = $dim-mix ?? ( $dim-mix (+) $add-mix ).MixHash !! $add-mix; } dd $dim-mix; Now I look at this paraphrased code, perhaps there is some formulation of ternary ?? !! that can avoid spelling out $dim-mix in the test since already on the left? Many thanks for any advice! By clicking ...

How to open a file handle on a string in Perl 6?

Image
Clash Royale CLAN TAG #URR8PPP How to open a file handle on a string in Perl 6? In Perl 5, I can open a filehandle on string like this: open my $kfh, "<", $message->payload; I have a scenario that uses string as a filehandle and passes it to the open method: open my $fh = new IO::Zlib; open my $kfh, "<", $message->payload; if($fh->open($kfh, 'rb')){ print <$fh>; $fh->close; } where $message->payload is read from Kafka, and the content is a byte array. raiph had a similar question, but it didn't answer my question. $message->payload So I want to know how to open a filehandle on a string in Perl 6 like Perl 5 does? These documentation pages have no information on this: The documentation has a section about this under Input/Output. – callyalater Jul 18 at 17:22 ...

How to insert separators between columns?

Image
Clash Royale CLAN TAG #URR8PPP How to insert separators between columns? I have columns in @columns : @columns my @columns =('column1', 'column2', 'column3'); and I have separators in @separators : @separators my @separators = (',', '|'); I want to insert the separators between columns, one by one: column1,column2|column my solution is: (@columns »~» (|@separators,"")).join("") Here I have three columns and two separators, and how about insert N-1 separators between N columns? N-1 N You could try say ((@columns Z @separators), @columns[*-1]).flat.join("") – Håkon Hægland 15 hours ago say ((@columns Z @separators), @columns[*-1]).flat.join("") @HåkonHægland Thanks, have fixed the typo ^_^ – chenyf ...