Re: using run

2018-06-20 Thread Jonathan Scott Duff
If you don't specify the :out adverb, then the output of the program you
are running will be sent to standard output.  Immediately when the program
executes.  If you specify the :out adverb, output from the program will be
available for capture via the $proc.out method.  A similar thing applies
for standard error.

A way to write the captured output to a file would be something like:

my $proc = run 'echo', 'foo bar baz', :out;
spurt("some-file-name", $proc.out.slurp(:close));

.slurp() will read all of the contents of the handle and return a string
(:close closes the file handle after reading everything).
spurt will write a string to a file.

hope this helps,

-Scott


On Wed, Jun 20, 2018 at 10:33 AM Theo van den Heuvel 
wrote:

> Hi all,
>
> trying to make sense of the documentation on run:
> https://docs.perl6.org/routine/run.
> In particular the last part. I don't  understand the adverbs :out and :
> err there.
> Can I set it up so that the output is piped into a file directly? If so
> how would I write that?
>
> I know I could use shell for that, but I doubt that is necessary.
>
> [On first reading I found the doc confusing because it start with a
> hairy example. WHy would anyone wish to write to a file named
> '>foo.txt'? How can that be the first example?]
>
> Thanks,
>
> --
> Theo van den Heuvel
>


Re: need s/ help

2018-05-01 Thread Jonathan Scott Duff
On Tue, May 1, 2018 at 8:37 AM, ToddAndMargo  wrote:

> Hi All,
>
> I am trying to change the last three letters of a string
>
> $ perl6 -e 'my $x="abcabcabc"; $x ~~ s/"a.*"$/xyz/; say $x;'
>

The double quotes around your text make it a string literal, so it will
only match the literal string "a.*" at the end of the string.

➤ perl6 -e 'my $x="abcabca.*"; $x ~~ s/"a.*"$/xyz/; say $x;'
abcabcxyz

Another way you could accomplish your goal (other than the ones already
mentioned elsewhere) is to use (.*) at the front of the regex to greedily
match and capture as much as possible until the "a", then match the rest of
the string and replace it with what you matched plus "xyz" ...

➤ perl6 -e 'my $x="abcabcabc"; $x ~~ s/(.*)a.*$/$0xyz/; say $x;'
abcabcxyz

Though, this could copy a significant amount of text depending on the part
of the string before that final "a".  Also, there could be significant
backtracking depending on the part of the string after that final "a".
But, sometimes it's a useful technique, so I mention it.

cheers,

-Scott




> abcabcabc
>
> I want abcabcxyz
>
> And, in real life, only the "a" will be a know letter.
> Everything else will vary.  And the "a" will repeat a lot.
> I am only interested in changing the last "a" and everything
> that comes after it.
>
> Many thanks,
> -T
>


Re: Does words have a delimiter?

2018-04-14 Thread Jonathan Scott Duff
Looking at that page myself, it doesn't appear that you can specify the
separator for .words.  So ... no.

Though, that would make an interesting addition IMHO

-Scott

On Sat, Apr 14, 2018 at 12:27 AM, ToddAndMargo 
wrote:

> Hi All,
>
> I am over on
> https://docs.perl6.org/routine/words
> and I can't make heads of tails out of it.
>
> Does "words" have a delimiter, as does "-F" with awk?
>
> Many thanks,
> -T
>


Re: learning perl6?

2016-01-04 Thread Jonathan Scott Duff
If, by "regular book", you mean "bound paper sheafs with ink on them", then
the answer is currently "no".   Is there something wrong with the
documentation online? (besides there not being enough of it :)

-Scott

On Mon, Jan 4, 2016 at 9:55 PM, Yonghua Peng  wrote:

> Hello,
>
> Is there a regular book, rather than the documentation online, for
> learning perl6?
>
> Thanks.
>


Re: grep changes?

2015-10-05 Thread Jonathan Scott Duff
The block does get the topic, but the regex isn't executing immediately.
Another way to get what you want, rather than mentioning the topic
explicitly, is to use the m// form of match.

> grep { m/\.pl6/ },  
(a.pl6)

For sanity's sake, I would recommend writing your match-immediately regex
like this everywhere as there's no potential ambiguity based on context.

As to whether or not the behavior you observe is correct ... I tend to
think that it is not correct.  S05 says

Specifically, a C matches immediately in a value context (sink,
Boolean, string, or numeric), or when it is an explicit argument of
a C<~~>.  Otherwise it's a C constructor identical to the explicit
C form.

The block is being evaulated in a boolean context, and I would expect that
to propagate to the innards of the block which would put the regex in a
boolean context.

-Scott

On Fri, Oct 2, 2015 at 1:50 PM, mt1957  wrote:

> Hi Philip,
>
> Thanks for your answer. Seems that I've written it wrongly then. Doesn't
> the block get the topic variable in the same way like map or can't the
> block be used there at all?
>
> Greetings
> Marcel
>
> Grep still accepts a regex, so `grep /\.pl6/, ` does what you
> want.
>
> On Fri, Oct 2, 2015 at 5:12 PM mt1957 < mt1...@gmail.com>
> wrote:
>
>> Hi,
>> noticed that grep doesn't accept a Match operation anymore
>> In repl ...
>>
>>  > grep { /\.pl6/ },  
>> Method 'match' not found for invocant of class 'Any'
>>
>> Must now do explicitly match on the topic variable
>>
>>  > grep { $_ ~~ /\.pl6/ },  
>> (a.pl6)
>>
>> Is this change correct?
>>
>> perl6 version 2015.09-206-g8a195fa built on MoarVM version
>> 2015.09-39-g1434283
>>
>> Greets,
>> Marcel
>>
>
>


Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread Jonathan Scott Duff
I imagine it's the same problem as this Perl 5 code:

use Test::More;

for ('GATGGAACTTGACTACGTAAATT') {
s/T/U/g;
is $_, 'GAUGGAACUUGACUACGUAAAUU', 'RNA';
}


Since $_ is an alias for each element of the list and the only element in
the list is a constant string and you can't modify constants, you get the
error.  Changing your code to:

use v6;
use Test;

my $x = 'GATGGAACTTGACTACGTAAATT';
for $x {
s:g/T/U/;
is $_ , 'GAUGGAACUUGACUACGUAAAUU' , 'RNA';
}


Does indeed work.

Though, if what I said is true, the error message is Less Than Awesome.  I
wonder could it be made more helpful?

Hope this helps,

-Scott


On Wed, Oct 24, 2012 at 7:35 AM, Marc Chantreux kha...@phear.org wrote:

 hello perl6 people,

 On

 This is perl6 version 2012.09.1
 built on parrot 4.6.0 revision 0

 When i try to run

 use v6;
 use Test;
 for 'GATGGAACTTGACTACGTAAATT' {
 s:g/T/U/;
 is $_
 , 'GAUGGAACUUGACUACGUAAAUU'
 , 'RNA';
 }

 I get

 Cannot assign to a non-container
   in sub infix:= at src/gen/CORE.setting:11692
   in block at /tmp/ZZZ:4

 As far as i understand from the doc, s:g/T/U/ is a valid syntax. any idea?

 regards
 marc



Re: Current vs future Perl 6 binary size

2011-04-21 Thread Jonathan Scott Duff
On Thu, Apr 21, 2011 at 6:33 PM, gvim gvi...@gmail.com wrote:

 This is not a criticism of anything. I am not a core developer but need to
 be aware of what to expect when Perl 6 settles down into a production-ready
 state. The Perl 6 binary within the January release of Rakudo Star is 10Mb
 on my Snow Leopard system. Do I take it that the Perl 6 binary is, by
 design, much larger than the current Perl 5.12 (1.6Mb) or is it simply that
 the Perl 6 binary is likely to lose more weight during the refinement
 process? In other words, is there a ballpark for how big the Perl 6 binary
 will be when development settles down?


I doubt anyone can tell you how big the binary will be with any degree of
certainty.

WRT the size of your Perl 5 binary ... how big is your libperl?  A good
chunk of the work also lives there.  For instance, on my system,
/usr/bin/perl is about 1.2 mb and /usr/lib/libperl.so.5.10.1 is about 1.4
mb.  (and Rakudo Perl 6 is about 5.6 mb).

I don't know about any of the other Perl 6 implementations, but Rakudo Perl
6 currently doesn't have a separate libperl6, nor is it highly optimized for
size or speed. Once that effort starts, it's anybody's guess as to what the
binary will look like.

I guess you could say it's that way by design because most of the effort
has been focused on the grand whirlpool of implementing the spec then
adjusting the spec once we have some experience with the implementation,
then implementing that new spec and so on.

hope this helps,

-Scott


Rakudo Perl 6 development release #22 (Thousand Oaks)

2009-10-23 Thread Jonathan Scott Duff
Announce: Rakudo Perl 6 development release #22 (Thousand Oaks)

On behalf of the Rakudo development team, I'm pleased to announce the
October 2009 development release of Rakudo Perl #22 Thousand Oaks.
Rakudo is an implementation of Perl 6 on the Parrot Virtual Machine
(see http://www.parrot.org).  The tarball for the October 2009 release
is available from http://github.com/rakudo/rakudo/downloads

Due to the continued rapid pace of Rakudo development and the frequent
addition of new Perl 6 features and bugfixes, we recommend building Rakudo
from the latest source, available from the main repository at github.
More details are available at http://rakudo.org/how-to-get-rakudo.

Rakudo Perl follows a monthly release cycle, with each release code
named after a Perl Mongers group.  The October 2009 is code named
Thousand Oaks for their amazing Perl 6 hackathon, their report at
http://www.lowlevelmanager.com/2009/09/perl-6-hackathon.html, and
just because I like the name :-)

Since the 2009-08 release, Rakudo Perl builds from an installed Parrot
instead of using Parrot's build tree.  This means that, unlike previous
versions of Rakudo Perl, the perl6 (or perl6.exe) executables only
work when invoked from the Rakudo root directory until a make install
is performed.  Running make install will install Rakudo and its
libraries into the Parrot installation that was used to build it, and
then the executables will work when invoked from any directory.

This release of Rakudo requires Parrot 1.7.0.

For the latest information on building and using Rakudo Perl, see the
readme file section titled Building and invoking Rakudo.  (Quick note:
the --gen-parrot option still automatically downloads and builds
Parrot as before, if you prefer that approach.)

Some of the specific changes and improvements occuring with this
release include:

* Rakudo is now passing 32,582 spectests, an increase of 17,085 passing
  tests since the September 2009 release.  With this release Rakudo is
  now passing 85.0% of the available spectest suite.

* We have a huge increase in the number of spectests relating to the
  Complex and Rat numeric types.

* Complex numbers are now implemented as a Perl 6 class, and supports all
  trigonometric functions from the specification.

* Rakudo has a new signature binder which makes calling routines
  and operators much faster, and allows binding of positional
  arguments by name.

* Rakudo has improved signature introspection, better errors relating to
  signatures and signature literals are now supported.

* Rakudo now supports accessing outer lexical variables from classes and
  packages.

* Some new variants of the series operator are now implemented.

* When configuring Rakudo with --gen-parrot, the --optimize flag is now
  passed to Parrot's Configure.pl

The development team thanks all of our contributors and sponsors for
making Rakudo Perl possible.  If you would like to contribute,
see http://rakudo.org/how-to-help , ask on the perl6-compi...@perl.org
mailing list, or ask on IRC #perl6 on freenode.

The next release of Rakudo (#23) is scheduled for November 19, 2009.
A list of the other planned release dates and codenames for 2009 is
available in the docs/release_guide.pod file.  In general, Rakudo
development releases are scheduled to occur two days after each
Parrot monthly release.  Parrot releases the third Tuesday of each month.

Have fun!


-Scott
-- 
Jonathan Scott Duff
perlpi...@gmail.com


Re: [ANNOUNCE] Pugs 6.2.12 and v6.pm released! (reformatted)

2006-07-10 Thread Jonathan Scott Duff
On Mon, Jul 10, 2006 at 09:37:24AM -0500, Michael Goldshteyn wrote:
 Audrey Tang [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
 
 Unfortunatelly, those of us who use Perl under Windows / MSVC Compiler 
 cannot use v6.pm, due to the fact that it has an indirect dependency on 
 Devel::Caller which fails to work using that compiler combination (i.e., 
 fails all tests after a build using its makefile and Visual Studio 2003 as 
 the C compiler).

Bummer. You could check out the Vanilla/Strawberry Perl effort at
http://win32.perl.org/

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]


Re: Mutil Method Questions

2006-06-23 Thread Jonathan Scott Duff
On Fri, Jun 23, 2006 at 06:18:51PM +0300, Markus Laire wrote:
 multi sub talk (String $msg1, String $msg2) { say $msg1 $msg2 }
 multi sub talk (String $msg, Int $times) { say $msg x $times; }
 multi sub talk (String $msg, Num $times) { say Please use an integer; }
 multi sub talk (String $msg, Range $r) { say $_: $msg for $r }
 
 talk(Hello, World); # String and String
 talk(Hi, 2); # String and Int
 talk(Test, 1.23); # String and Num
 talk(Hello, 3..5); # String and Range
 talk(123, 3); # Int and Int
 
 I think that would print
  Hello World
  HiHi
  Please use an integer
  3: Hello
  4: Hello
  5: Hello
  123123123
 
 In last example, there is no exact match for parameters (Int, Int), so
 IMHO perl6 would select the closest match, which in this case is
 (String, Int) because Int can be converted to String.

An alternate interpretation would be that the last one is actually a compile-
time error because none of the sigs match (Int,Int) and for a call to
work with 2 Int parameters, you'd need to be explicit:

talk(~123,3);

But I'm not sure which way perl6 actually leans.  

Though it seems to me that automatic type conversion by the compiler is
a way to get yourself in trouble.  Not that perl shouldn't let the
programmer get himself in trouble, but this seems like one of those
things that should require asking to turn on rather than asking to
turn off.

my two cents,

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]