Re: Need help with a match

2017-03-13 Thread Richard Hainsworth

Seems to me because the second '(' is not preceded by a space; it is '`('.

But if the second '(' was eg '` (', then the longest match would have 
been picked and a ? would be necessary.



On Tuesday, March 14, 2017 11:21 AM, ToddAndMargo wrote:

On 03/13/2017 08:16 PM, ToddAndMargo wrote:

On 03/13/2017 07:53 PM, yary wrote:
I think p6 regexes behave a bit like p5 regexes with the "x" flag 
turned

on, where whitespace can be added in for readability. To have literal
whitespace, put quotes around it. Like this (untested)


$x ~~ m/sub ' ' (.*) ' ' \(/;



Now that was way to easy and easy to read too.

Thank you!



Why did you get away with not having to use (.*?)  ?




Re: Need help with a match

2017-03-13 Thread ToddAndMargo

On 03/13/2017 08:16 PM, ToddAndMargo wrote:

On 03/13/2017 07:53 PM, yary wrote:

I think p6 regexes behave a bit like p5 regexes with the "x" flag turned
on, where whitespace can be added in for readability. To have literal
whitespace, put quotes around it. Like this (untested)


$x ~~ m/sub ' ' (.*) ' ' \(/;



Now that was way to easy and easy to read too.

Thank you!



Why did you get away with not having to use (.*?)  ?


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Need help with a match

2017-03-13 Thread ToddAndMargo

On 03/13/2017 07:53 PM, yary wrote:

I think p6 regexes behave a bit like p5 regexes with the "x" flag turned
on, where whitespace can be added in for readability. To have literal
whitespace, put quotes around it. Like this (untested)


$x ~~ m/sub ' ' (.*) ' ' \(/;



Now that was way to easy and easy to read too.

Thank you!


Re: Need help with a match

2017-03-13 Thread ToddAndMargo

On 03/13/2017 07:58 PM, Brandon Allbery wrote:

There is actually a third issue in that spaces are *ignored* in regexes,
so you actually end up with $/[0] eq ' Test'. Use the <.ws> rule to
avoid this. (The leading dot prevents that whitespace from additionally
being captured as $/ which here would be pointless. You might also
want one before the literal open paren so you don't also eat any spaces
there.)

#!/usr/bin/perl6
my $x='sub Test () { #`(Sub|63218616) ... }';
$x ~~ m/sub <.ws> (.*?) <.ws> \(/;


Thank you for the help!

Never could be  to work.  :'(


say "$x\n$0";


On Mon, Mar 13, 2017 at 10:52 PM, Brandon Allbery > wrote:

You have two problems:

(1) matches start from 0, not 1.


And I do know that.  Mumble, Mumble.  Short between the headsets


(2) .* gobbles as much as possible (this is also true in Perl 5) so
it matches to the ) at the end of (Sub|63218616). As in Perl 5, you
add a ? to make it take the shortest match instead:



 worked when I added your ? to the gobble


Thank you for the help!


Re: Need help with a match

2017-03-13 Thread Brandon Allbery
There is actually a third issue in that spaces are *ignored* in regexes, so
you actually end up with $/[0] eq ' Test'. Use the <.ws> rule to avoid
this. (The leading dot prevents that whitespace from additionally being
captured as $/ which here would be pointless. You might also want one
before the literal open paren so you don't also eat any spaces there.)

#!/usr/bin/perl6
my $x='sub Test () { #`(Sub|63218616) ... }';
$x ~~ m/sub <.ws> (.*?) <.ws> \(/;
say "$x\n$0";


On Mon, Mar 13, 2017 at 10:52 PM, Brandon Allbery 
wrote:

> You have two problems:
>
> (1) matches start from 0, not 1.
> (2) .* gobbles as much as possible (this is also true in Perl 5) so it
> matches to the ) at the end of (Sub|63218616). As in Perl 5, you add a ?
> to make it take the shortest match instead:
>
> #!/usr/bin/perl6
> my $x='sub Test () { #`(Sub|63218616) ... }';
> $x ~~ m/sub (.*?) \(/;
> say "$x\n$0";
>
>
>
> On Mon, Mar 13, 2017 at 10:46 PM, ToddAndMargo 
> wrote:
>
>> Hi All,
>>
>>
>> Just as soon as I think I understand it, a little
>> humility fall into my lap!
>>
>> 
>> #!/usr/bin/perl6
>> my $x='sub Test () { #`(Sub|63218616) ... }';
>> $x ~~ m/sub (.*) \(/;
>> say "$x\n$1";
>> 
>>
>> $ WhoTest2.pl6
>> Use of Nil in string context
>>   in block  at ./WhoTest2.pl6 line 4
>> sub Test () { #`(Sub|63218616) ... }
>>
>>
>> This is what I want to do. "sub " will
>> always be repeated and have a space after it.
>>
>> " (" will always be repeated and have a space before
>> it.
>>
>> I want what occurs between "sub " and " ("
>>
>> What am I doing wrong?  This time?
>>
>>
>> Many thanks,
>> -T
>>
>>
>> --
>> ~~~
>> Serious error.
>> All shortcuts have disappeared.
>> Screen. Mind. Both are blank.
>> ~~~
>>
>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>



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


Re: Need help with a match

2017-03-13 Thread Brandon Allbery
You have two problems:

(1) matches start from 0, not 1.
(2) .* gobbles as much as possible (this is also true in Perl 5) so it
matches to the ) at the end of (Sub|63218616). As in Perl 5, you add a ? to
make it take the shortest match instead:

#!/usr/bin/perl6
my $x='sub Test () { #`(Sub|63218616) ... }';
$x ~~ m/sub (.*?) \(/;
say "$x\n$0";



On Mon, Mar 13, 2017 at 10:46 PM, ToddAndMargo 
wrote:

> Hi All,
>
>
> Just as soon as I think I understand it, a little
> humility fall into my lap!
>
> 
> #!/usr/bin/perl6
> my $x='sub Test () { #`(Sub|63218616) ... }';
> $x ~~ m/sub (.*) \(/;
> say "$x\n$1";
> 
>
> $ WhoTest2.pl6
> Use of Nil in string context
>   in block  at ./WhoTest2.pl6 line 4
> sub Test () { #`(Sub|63218616) ... }
>
>
> This is what I want to do. "sub " will
> always be repeated and have a space after it.
>
> " (" will always be repeated and have a space before
> it.
>
> I want what occurs between "sub " and " ("
>
> What am I doing wrong?  This time?
>
>
> Many thanks,
> -T
>
>
> --
> ~~~
> Serious error.
> All shortcuts have disappeared.
> Screen. Mind. Both are blank.
> ~~~
>



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