Re: How do I remove leading zeros?

2018-06-13 Thread Brandon Allbery
https://docs.perl6.org/language/regexes#Capture_markers:_%3C(_)%3E

On Wed, Jun 13, 2018 at 3:10 PM Xin Cheng  wrote:

> Now we know the meaning of >> and <<. But what about <( and )> ? What do
> they mean here?
>
> Thanks.
> Xin
>
> On Jun 13, 2018, at 2:18 PM, Brad Gilbert  wrote:
>
> On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo 
> wrote:
>
>
> On 06/13/2018 11:06 AM, ToddAndMargo wrote:
>
> On 06/13/2018 11:03 AM, ToddAndMargo wrote:
>
> On 06/13/2018 11:00 AM, Larry Wall wrote:
>
>
>$ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
>1.0.103.6.10
>
>
> Hi Larry,
>
> How did you get thee "«" character to appear?  And
> what does it mean?
>
>
> The way I type them is [compose] [<] [<], which is nice because their
> ASCII equivalent is <<
>
> It means match a word boundary with the word being on the right side.
>
> say 'ABC DEF ' ~~ m:g/ << . /
>
>(「A」 「D」)
>
> say 'ABC DEF ' ~~ m:g/ >> . /
>
>(「 」 「 」)
>
>
>

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


Re: How do I remove leading zeros?

2018-06-13 Thread Xin Cheng
Now we know the meaning of >> and <<. But what about <( and )> ? What do they 
mean here?

Thanks.
Xin

> On Jun 13, 2018, at 2:18 PM, Brad Gilbert  wrote:
> 
> On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo  > wrote:
>> 
>> On 06/13/2018 11:06 AM, ToddAndMargo wrote:
>>> On 06/13/2018 11:03 AM, ToddAndMargo wrote:
 On 06/13/2018 11:00 AM, Larry Wall wrote:
>> 
>>>$ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
>>>1.0.103.6.10
>> 
>> Hi Larry,
>> 
>> How did you get thee "«" character to appear?  And
>> what does it mean?
>> 
> 
> The way I type them is [compose] [<] [<], which is nice because their
> ASCII equivalent is <<
> 
> It means match a word boundary with the word being on the right side.
> 
>> say 'ABC DEF ' ~~ m:g/ << . /
>(「A」 「D」)
>> say 'ABC DEF ' ~~ m:g/ >> . /
>(「 」 「 」)



Re: How do I remove leading zeros?

2018-06-13 Thread ToddAndMargo

On 06/13/2018 11:18 AM, Brad Gilbert wrote:

On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo  wrote:


On 06/13/2018 11:06 AM, ToddAndMargo wrote:

On 06/13/2018 11:03 AM, ToddAndMargo wrote:

On 06/13/2018 11:00 AM, Larry Wall wrote:



 $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
 1.0.103.6.10


Hi Larry,

  How did you get thee "«" character to appear?  And
what does it mean?



The way I type them is [compose] [<] [<], which is nice because their
ASCII equivalent is <<

It means match a word boundary with the word being on the right side.

 > say 'ABC DEF ' ~~ m:g/ << . /
 (「A」 「D」)
 > say 'ABC DEF ' ~~ m:g/ >> . /
 (「 」 「 」)




$ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/<<0+)>\d//; say "$x"'
1.0.103.6.10

Thank you!


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


Re: How do I remove leading zeros?

2018-06-13 Thread Brad Gilbert
On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo  wrote:
>
> On 06/13/2018 11:06 AM, ToddAndMargo wrote:
> > On 06/13/2018 11:03 AM, ToddAndMargo wrote:
> >> On 06/13/2018 11:00 AM, Larry Wall wrote:
>
> > $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
> > 1.0.103.6.10
>
> Hi Larry,
>
>  How did you get thee "«" character to appear?  And
> what does it mean?
>

The way I type them is [compose] [<] [<], which is nice because their
ASCII equivalent is <<

It means match a word boundary with the word being on the right side.

> say 'ABC DEF ' ~~ m:g/ << . /
(「A」 「D」)
> say 'ABC DEF ' ~~ m:g/ >> . /
(「 」 「 」)


Re: How do I remove leading zeros?

2018-06-13 Thread Brandon Allbery
https://docs.perl6.org/language/unicode_entry

I have right Alt set as my Compose key, so it'd be [right-Alt] < <

(At some point I should see if I can put in some information about
WinCompose, since I think I'm currently the only one with any experience
with it.)

On Wed, Jun 13, 2018 at 2:09 PM ToddAndMargo  wrote:

> On 06/13/2018 11:06 AM, ToddAndMargo wrote:
> > On 06/13/2018 11:03 AM, ToddAndMargo wrote:
> >> On 06/13/2018 11:00 AM, Larry Wall wrote:
>
> > $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
> > 1.0.103.6.10
>
> Hi Larry,
>
>  How did you get thee "«" character to appear?  And
> what does it mean?
>
> Many thanks,
> -T
>


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


Re: How do I remove leading zeros?

2018-06-13 Thread ToddAndMargo

On 06/13/2018 11:06 AM, ToddAndMargo wrote:

On 06/13/2018 11:03 AM, ToddAndMargo wrote:

On 06/13/2018 11:00 AM, Larry Wall wrote:



    $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
    1.0.103.6.10


Hi Larry,

How did you get thee "«" character to appear?  And
what does it mean?

Many thanks,
-T


Re: How do I remove leading zeros?

2018-06-13 Thread ToddAndMargo

On 06/13/2018 11:03 AM, ToddAndMargo wrote:

On 06/13/2018 11:00 AM, Larry Wall wrote:

I'd probably just write something like:

 s:g { « <( 0+ )> \d+ » } = '';

The first <( and the last » are not strictly necessary, but add 
clarity, or
at least balance.  But in golf mode you could get away with something 
like:


 sg/«0+)>\d//;

Larry




Awesome!  Thank you!

$ p6 'my $x = "01.0.103.06.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
1.0.103.6.10

What did you just do?



Sweet!

   $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
   1.0.103.6.10


Re: How do I remove leading zeros?

2018-06-13 Thread ToddAndMargo

On 06/13/2018 11:00 AM, Larry Wall wrote:

I'd probably just write something like:

 s:g { « <( 0+ )> \d+ » } = '';

The first <( and the last » are not strictly necessary, but add clarity, or
at least balance.  But in golf mode you could get away with something like:

 sg/«0+)>\d//;

Larry




Awesome!  Thank you!

$ p6 'my $x = "01.0.103.06.10"; $x ~~ s:g/«0+)>\d//; say "$x"'
1.0.103.6.10

What did you just do?


Re: How do I remove leading zeros?

2018-06-13 Thread ToddAndMargo

On 06/12/2018 10:22 PM, Norman Gaywood wrote:
On Wed, 13 Jun 2018 at 14:57, ToddAndMargo > wrote:


I am trying to turn

      01.02.03

into

      1.2.3

What am I doing wrong, this time?

$ p6 'my $x="01.02.03"; $x ~~ s:global/"0"(\d)/ $0 /; say "$x"'
   1 . 2 . 3


The second part of the s/// operator is a string (spaces count), not a 
regex (spaces ignored).


 > my $x="01.02.03"; $x ~~ s:global/"0"(\d)/$0/; say "$x"
1.2.3



Thank you!

$ p6 'my $x = "01.0.3.06.10"; $x ~~ s:global/"0"(\d)/$0/; say "$x"'
1.0.3.6.10


Re: How do I remove leading zeros?

2018-06-13 Thread Larry Wall
I'd probably just write something like:

s:g { « <( 0+ )> \d+ » } = '';

The first <( and the last » are not strictly necessary, but add clarity, or
at least balance.  But in golf mode you could get away with something like:

sg/«0+)>\d//;

Larry


Re: How do I remove leading zeros?

2018-06-13 Thread Mark Senn
If $x is set to "01.02.03"

(Not using normal message quoting to make message shorter.
[1] ToddAndMargo[2] Norman Gaywood[3] Mark Senn)

DOING $x ~~ s:global/"0"(\d)/ $0 /;  [1]
SETS $x TO"1 . 2 . 3"[1]
COMMENT   Spaces on right hand side of s command are significant.[2]

DOING $x ~~ s:global/"0"(\d)/$0/;[2]
SETS $x to"1.2.3"[2]
COMMENT   Zeroes would de deleted from "101.102.103".[3]

(I suspect the general case is delete leading zeroes or zeroes
immediately following periods.)

DOING $x ~~ s:g/(^|".")0+/$0/;   [3]
  or, using named captures,
  $x ~~ s:g/$=(^|".")0+/$/;
SETS $x to"1.2.3"[3]
COMMENT   Zeroes would not be deleted from "101.102.103".[3]

For me, the last solution is the clearest: replace all beginning of
strings or "."  followed by one or more zeroes by the beginning of the
string or ".", whichever was matched.

-mark


Re: How do I remove leading zeros?

2018-06-12 Thread ToddAndMargo

On 06/12/2018 09:56 PM, ToddAndMargo wrote:

Hi All,

I am trying to turn

     01.02.03

into

     1.2.3

What am I doing wrong, this time?

$ p6 'my $x="01.02.03"; $x ~~ s:global/"0"(\d)/ $0 /; say "$x"'
  1 . 2 . 3


Many thanks,
-T





Got it:

$ p6 'my $x = "01.0.3.06.10"; say ($x.comb(/\d+/)>>.Int).join(".");'
1.0.3.6.10



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


Re: How do I remove leading zeros?

2018-06-12 Thread Norman Gaywood
On Wed, 13 Jun 2018 at 14:57, ToddAndMargo  wrote:

> I am trying to turn
>
>  01.02.03
>
> into
>
>  1.2.3
>
> What am I doing wrong, this time?
>
> $ p6 'my $x="01.02.03"; $x ~~ s:global/"0"(\d)/ $0 /; say "$x"'
>   1 . 2 . 3
>
>
The second part of the s/// operator is a string (spaces count), not a
regex (spaces ignored).

> my $x="01.02.03"; $x ~~ s:global/"0"(\d)/$0/; say "$x"
1.2.3

-- 
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html