A s/// brain teaser to share

2018-05-01 Thread ToddAndMargo
Hi All, You guys will noticed a bunch of things you have been helping me with in the following. Thank you! :-) I have been working on cleaning up the file transfer of data from a point of sale software (POS) program to a label printer. The customer puts his margin on the end of the

Re: .sub confusion

2018-05-01 Thread JJ Merelo
Can you please take this very interesting question (and the rest the answers) to StackOverflow? Cheers JJ

Re: .sub confusion

2018-05-01 Thread Brandon Allbery
On Tue, May 1, 2018 at 4:49 AM, ToddAndMargo wrote: > .sub is a method call and I can't write them. They come with Perl. > You can write them. But they are 'method', not 'sub', and must be defined within a class. If you put 'is export' on a method so defined, it can

Re: odd and even

2018-05-01 Thread Brandon Allbery
On Tue, May 1, 2018 at 9:17 PM, Larry Wall wrote: > On Tue, May 01, 2018 at 01:43:44AM -0700, ToddAndMargo wrote: > : The worst thing I had problems with in Perl was folks telling it > : was "Lexiconical". What? I wish they would have also said "which > : means Perl figures out

Re: odd and even

2018-05-01 Thread ToddAndMargo
On 05/01/2018 06:17 PM, Larry Wall wrote: On Tue, May 01, 2018 at 01:43:44AM -0700, ToddAndMargo wrote: : The worst thing I had problems with in Perl was folks telling it : was "Lexiconical". What? I wish they would have also said "which : means Perl figures out your variables type on the fly,

Re: odd and even

2018-05-01 Thread Brent Laabs
Yeah, that lexiconic section sounded a bit hyperbolic. On Tue, May 1, 2018 at 6:17 PM, Larry Wall wrote: > On Tue, May 01, 2018 at 01:43:44AM -0700, ToddAndMargo wrote: > : The worst thing I had problems with in Perl was folks telling it > : was "Lexiconical". What? I wish

Re: odd and even

2018-05-01 Thread Larry Wall
On Tue, May 01, 2018 at 01:43:44AM -0700, ToddAndMargo wrote: : The worst thing I had problems with in Perl was folks telling it : was "Lexiconical". What? I wish they would have also said "which : means Perl figures out your variables type on the fly, so you don't : have to type cast

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On 05/01/2018 05:19 PM, Brent Laabs wrote: That last one has a special case available, but it's slightly less portable.  But afaik it works on all platforms we actually support: > perl6 -e '"screws/nuts/bolts/washers".path.parent.Str.say' screws/nuts/bolts :-)

Re: need s/ help

2018-05-01 Thread Brent Laabs
That last one has a special case available, but it's slightly less portable. But afaik it works on all platforms we actually support: > perl6 -e '"screws/nuts/bolts/washers".path.parent.Str.say' screws/nuts/bolts On Tue, May 1, 2018 at 4:37 PM, ToddAndMargo wrote: > On

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On 05/01/2018 04:29 PM, ToddAndMargo wrote: On Tue, 1 May 2018 at 14:37 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;'    

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, 1 May 2018 at 14:37 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;' abcabcabc I want abcabcxyz And, in

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On 05/01/2018 01:46 PM, Jonathan Scott Duff wrote: perl6 -e 'my $x="abcabca.*"; $x ~~ s/"a.*"$/xyz/; say $x;' There is no ".*" in the string ($x="abcabca.*")

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

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, 1 May 2018 at 14:37 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;' abcabcabc I want abcabcxyz And, in

Re: need s/ help

2018-05-01 Thread ToddAndMargo
On Tue, May 1, 2018 at 3:54 PM Simon Proctor > wrote: So what you what to match is a followed by zero or more not a's and then the end of the string. <[a]> is the perl6 regex for a range comprising of a alone you can

Re: need s/ help

2018-05-01 Thread Thomas Klausner
Hi! On Tue, May 01, 2018 at 04:03:24PM +, Fernando Santagata wrote: > I guess there are more ways to do that than I can count :-) Which reminds me of http://paris.mongueurs.net/aplusplus.html Greetings, domm -- #!/usr/bin/perl http://domm.plix.at for(ref

Re: need s/ help

2018-05-01 Thread Fernando Santagata
I guess there are more ways to do that than I can count :-) These two don't use a regex: ($a.comb)[0..^*-3].join ~ 'xyz'; # replace the last three letters of a string $a.subst: 'abc', 'xyz', :3rd; # replace the third occurrence of 'abc' On Tue, May 1, 2018 at 3:54 PM Simon Proctor

Re: need s/ help

2018-05-01 Thread Simon Proctor
So what you what to match is a followed by zero or more not a's and then the end of the string. <[a]> is the perl6 regex for a range comprising of a alone you can negate that like so <-[a]> Giving us perl6 -e 'my $x="abcabcabc"; $x ~~ s/a <-[a]>* $/xyz/; say $x;' (There's probably a better

need s/ help

2018-05-01 Thread ToddAndMargo
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;' 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

Re: odd and even

2018-05-01 Thread Parrot Raiser
The result of a modulus-2 is always going to be 0 or 1, so if you can put the "even" and "odd" results in a 2 -element array, using it as a subscript would be a way to achieve the outcome. On 5/1/18, ToddAndMargo wrote: > On 04/30/2018 06:47 AM, Elizabeth Mattijsen wrote:

Re: .sub confusion

2018-05-01 Thread ToddAndMargo
On 04/30/2018 06:20 AM, Elizabeth Mattijsen wrote: On 30 Apr 2018, at 15:04, ToddAndMargo wrote: Hi All, I am confused. With this sub: sub odd( $Num ) { return $Num % 2; } Why does this work: if odd $LineNum { $PartsStr ~= ''; } # Green

Re: .sub confusion

2018-05-01 Thread ToddAndMargo
On 04/30/2018 07:15 AM, Bruce Gray wrote: On Apr 30, 2018, at 8:04 AM, ToddAndMargo wrote: Hi All, I am confused. With this sub: sub odd( $Num ) { return $Num % 2; } Why does this work: if odd $LineNum { $PartsStr ~= ''; } # Green

Re: odd and even

2018-05-01 Thread ToddAndMargo
On 04/30/2018 06:47 AM, Elizabeth Mattijsen wrote: Perhaps this is a simpler solution: for split( "\n", $ClipStr ) -> $evenline, $oddline? { say “Purple $evenline”; say “Green $_” with $oddline; } Two lines at a time. Fascinating! Thank you!

Re: odd and even

2018-05-01 Thread ToddAndMargo
Please remember that I have about 1/100 of your skill when you explain things to me.  (For instance, I have no clue what `subset` is or how to use it.) -T On 04/30/2018 06:52 AM, Theo van den Heuvel wrote: > Hi Todd, > > different people have different ways of learning things. Diving into