perl6

Does changing Perl 6's $*OUT change standard output for child processes?

和自甴很熟 提交于 2019-12-08 15:30:12
问题 I was playing around with shell and how it acts when I change the standard filehandles in the calling program. Proc says: $in, $out and $err are the three standard streams of the to-be-launched program, and default to "-", which means they inherit the stream from the parent process. As far as I can tell, the external program doesn't use the same file handles: #!/Applications/Rakudo/bin/perl6 #`( make an external Perl 6 program the outputs to standard handles ) my $p6-name = 'in-out.p6'.IO;

What's the best way to be lax on whitespace in a perl6 grammar?

不羁的心 提交于 2019-12-08 15:29:09
问题 I want to have a grammar that is lax in whether whitespace is present or not... I want to match: this ' <foo> <bar> <baz> ' and also this '<foo><bar><baz>' This works: token TOP { \s* <foo> \s* <bar> \s* <baz> \s* } But after reading all about :sigspace, <.ws> and rule I can imagine that there is a way to do this without the repeated *\s . (viz. How do I match a hex array in per6 grammar) Please can someone tell me if there is nicer way to do this in a perl6 grammar? NB. this is not solved by

print sth every second, and also sleep 10 seconds very 5 seconds using react … whenever in Perl 6?

♀尐吖头ヾ 提交于 2019-12-08 15:17:07
问题 I want to print the current time every second, and also want to sleep 10 seconds very 5 seconds: react { whenever Supply.interval(1) { say DateTime.now.posix; } whenever Supply.interval(5) { sleep 10; say 'Sleep Done'; } whenever signal(SIGINT) { say "Done."; done; } } the output is not what i wanted: 1542371045 Sleep Done 1542371055 Sleep Done 1542371065 Sleep Done 1542371075 Done. ... what i want is this: 1542371045 1542371046 1542371047 1542371048 1542371049 Sleep Done 1542371059

perl6 IO::Socket::INET Could not receive data from socket: Connection reset by peer

大兔子大兔子 提交于 2019-12-07 19:36:03
问题 Sample server: #!/usr/bin/env perl6 my $listen = IO::Socket::INET.new(:listen, :localhost<localhost>, :localport(3333)); loop { my $conn = $listen.accept; while my $buf = $conn.recv(:bin) { $conn.write: $buf; } $conn.close; } Client: #!/use/bin/env perl6 my $c = IO::Socket::INET.new(:host<localhost>, :port(3333)); $c.print: "{time}\n"; #say $c.recv; #commented out on purpose sleep 1 ; $c.close ; server error: Could not receive data from socket: Connection reset by peer in block <unit> at

Passing regexes as arguments in Perl 6

爷,独闯天下 提交于 2019-12-07 10:34:53
问题 A continuation of this question, and probably an even more weird one. Can I e.g. concatenate two regexes using a sub ? (Of course, I understand, how to do it with a regex ) The following code is totally wrong, but I hope it can explain what I want to do: my Regex sub s12 ( $c, $v) { return / <{$c}> <{$v}> / } my regex consonant { <[a .. z] -[aeiou]> } my regex vowel { <[aeiou]> } my regex open_syllable { &s12( &consonant, &vowel ) } "bac" ~~ m:g/ <open_syllable> /; say $/; # should be 'ba'

How to define variable names dynamically in Perl 6?

拈花ヽ惹草 提交于 2019-12-07 10:34:52
问题 I have a name which I'd like to give to a variable, in another string variable: my $name = '$a'; or simply my $name = 'a'; How to make the variable and to use it? I mean something like this (but it doesn't work): my $name = '$a'; my {$name} = 1; # Doesn't work say $a; # should be 1 A more general case. I have a list of variable names, say my @names = '$aa' ... '$cc'; How to declare and use the variable, whose name will be e.g. @names[2] ? 回答1: According to documentation the lexical pad

Parsing binary structure with Perl6 Grammar

China☆狼群 提交于 2019-12-07 10:26:48
问题 What is the best option to parse a binary structure with Perl6 . in Perl5 we have the pack/unpack methods on Perl6 they seems experimental is it possible to use Perl6 grammar to parse binary data let's say i have a file which have records on the following binary format : struct record { short int ut_type; char ut_line[UT_LINESIZE]; char ut_id[4]; char ut_user[UT_NAMESIZE]; char ut_host[UT_HOSTSIZE]; } is it possible to parse this file with Perl6 grammar ? 回答1: What is the best option to parse

Start REPL with definitions loaded from file

本小妞迷上赌 提交于 2019-12-07 08:44:45
问题 Is there a way to start the Perl 6 REPL with definitions loaded from a file? I.e. let's say I have this in test.p6 : sub abc() { say 123; } I'd like to be able to start the perl6 REPL and load that file so that I can use abc interactively. 回答1: I guess the easiest way would be to put your code in a .pm6 file, e.g. ./Foo.pm6 , mark the subroutines in question with is export and then start Rakudo Perl 6 like this: $ perl6 -I. -MFoo To exit type 'exit' or '^D' > abc 123 来源: https://stackoverflow

Not able to serve jupyter notebooks in binder

你离开我真会死。 提交于 2019-12-07 08:23:41
问题 Binder project looks promising. It helps in executing notebooks in a github repository by building an executable container. I am trying to build an executable container in binder with the following Dockerfile that has Perl 6 and Python 3 kernels: FROM sumdoc/perl-6 ENV NB_USER jovyan ENV NB_UID 1000 ENV HOME /home/${NB_USER} RUN adduser --disabled-password \ --gecos "Default user" \ --uid ${NB_UID} \ ${NB_USER} RUN apt-get update \ && apt-get install -y build-essential \ git wget libzmq3-dev

perl6 'do(file)' equivalent

落花浮王杯 提交于 2019-12-07 05:46:28
问题 In perl5 I used to 'do (file)' for configuration files like this: ---script.pl start --- our @conf = (); do '/path/some_conf_file'; ... foreach $item (@conf) { $item->{rules} ... ... ---script.pl end --- ---/path/some_conf_file start --- # arbitrary code to 'fill' @conf @conf = ( {name => 'gateway', rules => [ {verdict => 'allow', srcnet => 'gw', dstnet => 'lan2'} ] }, {name => 'lan <-> lan2', rules => [ {srcnet => 'lan', dstnet => 'lan2', verdict => 'allow', dstip => '192.168.5.0/24'} ] }, )