Re: Array remove duplicates question

2024-05-06 Thread ToddAndMargo via perl6-users

On 5/6/24 05:45, yary wrote:

I thought you wanted them sorted also?

[1] > (8,7,6,7,5,4,2,1).unique
(8 7 6 5 4 2 1)
[2] > (8,7,6,7,5,4,2,1).unique.sort
(1 2 4 5 6 7 8)


-y


Hi Yary,

Not in this instance.  But the the command is
really sweet.  Thank you!

This time I am going the extract IP addresses from
a firewall log of hackers attacking my customer's
firewalls with a "Brute Force Attack", strip the
source port, remove the bazillions of duplicates,
add the location (city and country) of the
attacker, format an output such that their firewalls
can add them to the group deny list.  Does not matter
if the are sorted.

I will definitely use  your .sort if the future.
At least I will not have to make any API calls
this time.

Its a living.

-T

Oh ya, and install Multi Factor Authentication
too.  But no Raku needed for that.




Re: Array remove duplicates question

2024-05-06 Thread ToddAndMargo via perl6-users

On 5/6/24 03:07, ToddAndMargo via perl6-users wrote:


On 6 May 2024, at 04:35, ToddAndMargo via perl6-users 
 wrote:


Hi All,

I have thought of how to do it and pretty sure
it would work, but just in case Raku have one
of those sweet utilities, does Raku have a
utility that will take an array and remove all
the duplicates and rearrange the cells back
in order?

Many thanks,
-T


On 5/6/24 01:59, Elizabeth Mattijsen wrote:
 > $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a'
 > [1 2 3 6 7 8]
 >
 > https://docs.raku.org/type/Any#method_unique
 >

I knew there had to be something!   Thank you!


My keeper:  perl6.array.duplicates.unique.txt


Raku (perl6): how to remove duplicates from an array:

Use `unique` and `.=`

For example:

$ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a'
[1 2 3 6 7 8]

$ raku -e 'my @a = "abc","DEF","abc","jkl",1,2,8; @a .= unique; say @a'
[abc DEF jkl 1 2 8]

$ raku -e 'my @a = "abc","DEF","abc","jkl",1; @a .= unique; say @a'
[abc DEF jkl 1]

$ raku -e 'my @a = "abc","DEF","abc","jkl",1,8,1,2,8; @a .= unique; say @a'
[abc DEF jkl 1 8 2]




Re: Array remove duplicates question

2024-05-06 Thread ToddAndMargo via perl6-users




On 6 May 2024, at 04:35, ToddAndMargo via perl6-users  
wrote:

Hi All,

I have thought of how to do it and pretty sure
it would work, but just in case Raku have one
of those sweet utilities, does Raku have a
utility that will take an array and remove all
the duplicates and rearrange the cells back
in order?

Many thanks,
-T


On 5/6/24 01:59, Elizabeth Mattijsen wrote:
> $ raku -e 'my @a = 1,2,3,6,7,1,2,8; @a .= unique; say @a'
> [1 2 3 6 7 8]
>
> https://docs.raku.org/type/Any#method_unique
>

I knew there had to be something!   Thank you!



Re: Need regex ^? help

2024-05-06 Thread ToddAndMargo via perl6-users

This is what I have so far.

my $x="  1.2.3.4:12345   "; $x = $x.trim; $x~~s/(.*'.') 
.*/$0$(Q[0/24])/; say "<$x>";

<1.2.3.0/24>

It works. Is there a way to petty it up with ^ and $   ?




Array remove duplicates question

2024-05-05 Thread ToddAndMargo via perl6-users

Hi All,

I have thought of how to do it and pretty sure
it would work, but just in case Raku have one
of those sweet utilities, does Raku have a
utility that will take an array and remove all
the duplicates and rearrange the cells back
in order?

Many thanks,
-T




Re: Need regex ^? help

2024-04-29 Thread ToddAndMargo via perl6-users

On 4/29/24 17:57, Patrick R. Michaud wrote:

Perhaps not really what you're intending, but here's how I'd start:

 $ raku -e 'my $x="1.2.3.4"; $x ~~ s!\d+$!0/24!; say $x;'
 1.2.3.0/24

The pattern part of the substitution matches all of the digits at the end of the string 
(\d+$), then replaces them with the string "0/24".  Everything prior to those 
digits is left alone.

On Mon, Apr 29, 2024 at 05:45:49PM -0700, ToddAndMargo via perl6-users wrote:

On 4/29/24 17:42, ToddAndMargo via perl6-users wrote:

Hi All,

I thought I understood ^ and ? used in a regex'es,
but I don't.

^ means from the beginning and ? from the end.


I think you mean "$" here instead of "?".

Pm



Oh I did figure it out another way.  I am trying to
get a working example of ^ and $ for my Redex
keeper file


Re: Need regex ^? help

2024-04-29 Thread ToddAndMargo via perl6-users

On 4/29/24 17:42, ToddAndMargo via perl6-users wrote:

Hi All,

I thought I understood ^ and ? used in a regex'es,
but I don't.

^ means from the beginning and ? from the end.

I am trying to put together an example
of how to use them:

I have

    1.2.3.4

I want
    1.2.3.0/24

So Far I have (not working):

    raku -e 'my $x="1.2.3.4"; $x~~s/ (.*) $(Q[.]) /$0Q[0/24]/; say $x;'

How do I do this with ^ and $  ?

Many thanks,
-T



raku -e 'my $x="1.2.3.4"; $x~~s/ (.*) $(Q[.]) /$0$(Q[0.24])/; say $x;'
1.2.30.244





Need regex ^? help

2024-04-29 Thread ToddAndMargo via perl6-users

Hi All,

I thought I understood ^ and ? used in a regex'es,
but I don't.

^ means from the beginning and ? from the end.

I am trying to put together an example
of how to use them:

I have

   1.2.3.4

I want
   1.2.3.0/24

So Far I have (not working):

   raku -e 'my $x="1.2.3.4"; $x~~s/ (.*) $(Q[.]) /$0Q[0/24]/; say $x;'

How do I do this with ^ and $  ?

Many thanks,
-T


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


Re: Is irc.libera.chat down?

2024-04-19 Thread ToddAndMargo via perl6-users

A sex, 19-04-2024 às 03:09 -0700, Todd Chester via perl6-users
escreveu:

A sex, 19-04-2024 às 02:36 -0700, Todd Chester via perl6-users
escreveu:

Hi All,

Is
  https://kiwiirc.com/nextclient/irc.libera.chat/#raku
down?

-T




On 4/19/24 03:03, David Santiago wrote:
  >
  > It works for me.
  >
  > Regards,
  > David
  >

Hi David,

The circle just goes round and round and after
a while, it times out.

I tried both Firefox and Brave Browser.

I wonder if I got "quieted" or banned.   Is there
a way to tell?

-T


On 4/19/24 03:56, David Santiago wrote:
>
> Do you have any adblocker or any extension that blocks js? If so try to
> disable it.
>
> You can also use a dedicated client instead of the browser:
>
> www.mirc.com (for windows) or https://hexchat.github.io/ (for windows
> and linux).
>
>
> Regards,
> David Santiago

Hi David,

Did not help.  It is my username that is banned.

If memory serves, about a year ago, I logged into
it to ask a question  and someone screeded all over
me with a bunch of very creative insults.  I tried
to talk with him but got no answer back.  I did not
think much of it at the time.  I post on usenet a lot
and you develop a pretty thick skin.  After that
I was never able to get anyone to answer me.

So it is what it is.  I will jut use a different
username.  Maybe the libeler will be in a better
mood next time.

-T






Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/17/24 19:10, William Michels via perl6-users wrote:

Hi Todd,

Here are a few U StackExchange answers that I wrote using Raku's `unlink`:

https://unix.stackexchange.com/questions/459521/how-to-truncate-file-to-maximum-number-of-characters-not-bytes/751267#751267

https://unix.stackexchange.com/questions/749558/remove-exact-line-from-file-if-present-leave-the-rest-of-lines-error-handling/749581#749581

(Suggestions welcome).



Hi William,

unlink($_) if $bak.IO:e & $bak.IO:f;

Interesting!  Thank you.

The problem is that you can not implicitly trust
the file operations when programming on the kluge.
Linux, no problem.

I wish I had more Linux customers, but I do not.

-T

I do not know if you are, but I just append .tmp or .bak on to the name 
of my program.   I have never used Kernel32::GetTempTileNameA.


https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea


Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/17/24 05:52, yary wrote:

 From unlink's documentation:

If the file to be deleted does not exist, the routine treats it as success.

So trying to delete a file that isn't there, doesn't have an error, 
which is kind of neat, but that is a difference from native delete.


-y


Hi Yary,

Not to beat a dead horse, but when does that stop me!


In Windows, if the filename/path exceeds 260 characters
(MAX_PATH), unlink will think that the file does not
exist and will let you blissfully think it has been removed,
when in reality, it is still there.

-T


Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/17/24 05:52, yary wrote:

 From unlink's documentation:

If the file to be deleted does not exist, the routine treats it as success.

So trying to delete a file that isn't there, doesn't have an error, 
which is kind of neat, but that is a difference from native delete.


-y



Hi Yary,

Not neat at all.  And that would be a bug that need
to be fixed.  I spend hours trying to troubleshoot
why I could not delete a file.

1) it should return "File not Found"

and

2) it should return "MAX_PATH exceed in file name"
if that is the case and `\\?\` has not been prepended.
And if such, recommend adding `\\?\`.  Or just
add it automatically as my ApiDeleteFile module
does.


This is Windows we are dealing with after all.

Oh look how it is done in Linux when deleting a
non-existent file:

$ rm abc.txt ; echo $?
rm: cannot remove 'abc.txt': No such file or directory
1

The "No such file or directory" is self explanatory.

The "1" from the echo of "$?" means the command failed,
unlike the no error return from Raku's unlink.  Unlink
need to be fixed.

-T






Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/17/24 05:50, yary wrote:
What does the windows native delete do which you need, that raku's 
unlink doesn't have?


without unlink $FileName { say "Could not delete $FileName:", 
.exception.message };


-y


Hi Yary,

This is Windows we are dealing with.  It is a kluge.
I have had unlink fail and could not figure out why.

DeleteFileA has wonderful error reporting, well
for Windows.  And you can always count on it doing
things right.  Well, again, maybe..

What caused me to do all this was my inability to delete
the following from the command shell, powershell, and
(Raku) unlink.  But I could delete from Windows Explorer.
I kept getting told the command could not find
the file.   H!

D:\MyDocsBackup\backup2\Mozilla 2024-03-26 16;10;20 
(Full)\Firefox\Profiles\pj0elosu.default-release\storage\default\https+++505991220932649.webpush.freshchat.com^partitionKey=%%28https%%2Cbid13.com%%29\cache\morgue\114\{7cccd5e9-a7aa-4349-a2e9-569baf007272}.final


I had originally thought that the issue was the "weird" characters.
All my attempts to escape the failed.  So out of desperation,
I switched to DeleteFileA.

On DeleteFileA's web page was the give away:

'Tip  Starting with Windows 10, Version 1607, you can
opt-in to remove the MAX_PATH limitation without
prepending "\\?\"'

And I did not realize this a first, but a thorough reading
of the web page and I finally understood.  The file I
was trying to delete was 265 characters long and the
limit (MAX_PATH) was 260.  The commands I was trying
were lopping off five of the characters.  And the commands
did not tell me I had exceeded MAX_PATH.  (This is M$ we
are dealing with after all.)

Now you all that live sheltered lives with Linux, this would
not be an issue.  But the kluge, it is.  You can have to
different max lengths and you have to know when and when
not to prepend.  I am sorry, but what poor programming
on M$'s part.  (Prepending works on shorter files, but
takes longer to process and sometimes coughs.)

You will notice my modules a few things:

1) if the length of the path/name exceeds MAX_PATH and the
path/name does not include \\?\`, then I prepend it.

2) if DeleteFileA return pass, I send back "OK" in the
string.  If not, I send back the error message from
Kernel32::GetLastError" (returns a number) and
Kernel32::WinFormatMessage (translates the error
number to text).

So now I have a powerful tool in addition to unlink in my
tool box to cope with the kluge.

In Linux, I will use unlink, but in the kluge, I will probably
use my ApiDeleteFile.

It never hurts to have enough tools.

-T

Me wonders why Windows programmers do not tear
all their hair out.




Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/16/24 23:25, ToddAndMargo via perl6-users wrote:
`\\>\` should have been
`\\?\`



Re: need native call help

2024-04-17 Thread ToddAndMargo via perl6-users

On 4/16/24 20:57, ToddAndMargo via perl6-users wrote:


    $LongName = $FileName;
    if $FileName.chars >= MAX_PATH  { $LongName = Q[\\?\] ~ $FileName; }


What the about is all about is that MAX_PATH, which
limits the file name to 260 characters, can go up to
32,767 wide characters, prepend "\\?\" to the path.

I altered the above line since posting to:

   $LongName = $FileName;
   if $FileName.chars >= MAX_PATH  &&  not $FileName.starts-with( 
Q[\\?] )  {

   $LongName = Q[\\?\] ~ $FileName;
   }


in case I forget that my module prepends the `\\>\` if
I exceed MAX_PATH




Re: need native call help

2024-04-16 Thread ToddAndMargo via perl6-users

On 4/16/24 18:43, ToddAndMargo via perl6-users wrote:

On 4/16/24 01:21, ToddAndMargo via perl6-users wrote:

Hi All,

Windows 11

It has been so long that I have done one of these that
my brain is seizing.

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea

C++

BOOL DeleteFileA(
   [in] LPCSTR lpFileName
);


Would some kind soul please show me how to do this again?

Many thanks,
-T


I got a good night's sleep and my head unfroze.

I figured it out.  I will post back how in a
few days or so.

-T




Hi All,

https://docs.raku.org/language/nativecall
is a wonderful documeht, but as far as I can
tell, they do not breakdown how to make an
API call.  They expect you to already know how
to do it.  So not for the beginners.

This is the code I came up with.  There is a lot
of the my libraries missing from this, if you want
them, I can eMail them to you.  I am only posting
this so you can get the idea of how to do this:

-T

# unit module NativeDelete;
# NativeDelete.rakumod

#`{

   Delete a filed directory with the Windows DeleteFileA function
   (fileapi.h) API with NativeCall.


https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea
   https://docs.raku.org/language/nativecall

   To use, place the following at the top of your program:

   use NativeDelete :ApiDeleteFile;
   use NativeCall;
   use NativeConstants;
   use NativeConvert :to-UTF8-c-str;
   use WinErr :WinGetLastError, :WinFormatMessage;

   Test one liner:
  Note: in Windows Explorer, right click on the file, left click on 
copy as path,
then paste the entire path.  Note the `\\?\` at the 
beginning for long file names.


  K:\Windows\NtUtil>echo abc > eraseme.txt && raku -I. -e "use 
NativeDelete :ApiDeleteFile; say ApiDeleteFile( Q[eraseme.txt] )" && 
type eraseme.txt

  OK
  The system cannot find the file specified.

  K:\Windows\NtUtil>echo abc > eraseme.txt && raku -I. -e "use 
NativeDelete :ApiDeleteFile; say ApiDeleteFile( Q[eraseme2.txt] )" && 
type eraseme.txt

  The system cannot find the file specified.
  abc

  raku -I. -e "use NativeDelete :ApiDeleteFile; say ApiDeleteFile( 
Q[\\?\D:\MyDocsBackup\backup2\Mozilla 2024-04-15 21;14;31 
(Full)\Firefox\Profiles\pj0elosu.default-release\storage\default\https+++505991220932649.webpush.freshchat.com^partitionKey=%28https%2Cbid13.com%29\cache\morgue\114\{7cccd5e9-a7aa-4349-a2e9-569baf007272}.final] 
);"

  OK

}

use NativeCall;
use NativeConstants;
use NativeConvert :to-UTF8-c-str;
use WinErr :WinGetLastError, :WinFormatMessage;


sub DeleteFileA(
   #`{
   C++
 BOOL DeleteFileA(
 [in] LPCSTR lpFileName
   );
   }

   CArray[uint8] $lpFileName
   )
   is native("Kernel32.dll")
   is symbol("DeleteFileA")
   returns BOOL
   { * };


sub ApiDeleteFile( Str $FileName ) returns Str is export( :ApiDeleteFile ) {
#`{
$FileName is the file name and optional path path
Format:  Q[D:\NtUtil\eraseme.txt]   Note the backslashes.

Returned "OK" if successful or the error message if not

Syntax
C++

BOOL DeleteFileA(
   [in] LPCSTR lpFileName
);
DLL Kernel32.dll

Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero (0). To get 
extended error information, call GetLastError.


By default, the name is limited to MAX_PATH characters. To extend 
this limit to 32,767

wide characters, prepend "\\?\" to the path.

If using `\\?\` you must use the full path.

}

   my DWORD $LastError   = 0;
   my Str   $WinErrorMsg = "OK";
   my BOOL  $RtnValue= 1;
   my Str   $LongName= "";

   $LongName = $FileName;
   if $FileName.chars >= MAX_PATH  { $LongName = Q[\\?\] ~ $FileName; }

   my CArray[uint8] $lpFileName = to-UTF8-c-str( $LongName );
   $RtnValue = DeleteFileA( $lpFileName );

   sub GetLastError() is native("Kernel32") is symbol("GetLastError") 
returns DWORD { * };



   if $RtnValue == 0  {
  $LastError   = GetLastError();
  $WinErrorMsg = WinFormatMessage( $LastError );
   }
   return $WinErrorMsg;

}









Re: need native call help

2024-04-16 Thread ToddAndMargo via perl6-users

On 4/16/24 01:21, ToddAndMargo via perl6-users wrote:

Hi All,

Windows 11

It has been so long that I have done one of these that
my brain is seizing.

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea

C++

BOOL DeleteFileA(
   [in] LPCSTR lpFileName
);


Would some kind soul please show me how to do this again?

Many thanks,
-T


I got a good night's sleep and my head unfroze.

I figured it out.  I will post back how in a
few days or so.

-T



need native call help

2024-04-16 Thread ToddAndMargo via perl6-users

Hi All,

Windows 11

It has been so long that I have done one of these that
my brain is seizing.

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilea

C++

BOOL DeleteFileA(
  [in] LPCSTR lpFileName
);


Would some kind soul please show me how to do this again?

Many thanks,
-T


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


Re: I need sorting help

2024-03-16 Thread ToddAndMargo via perl6-users

On 3/2/24 05:13, Elizabeth Mattijsen wrote:

$ raku -e '.say for .sort(*.split(/\d+/, :kv).map({ (try 
.Numeric) // $_}).List)
afoo2
afoo12



On 2 Mar 2024, at 07:26, ToddAndMargo via perl6-users  
wrote:

Hi All,

@Sorted_List = @Sorted_List.sort: { .comb(/ \d+ | \D+ /) .map({ .Int // .self 
})};

gives me

   Element [0]  
   Element [1]  
   Element [2]  
   Element [3]  
   Element [4]  
   Element [5]  
   Element [6]  
   Element [7]  
   Element [8]  
   Element [9]  

I need it to say

   Element [0]  
   Element [1]  
   Element [2]  
   Element [3]  
   Element [4]  
   Element [5]  
   Element [6]  
   Element [7]  
   Element [8]  
   Element [9]  

What did I goof up, this time?

Many thanks,
-T





Hi Liz,

Look what you have done to me!

$ raku -e '.say for bk-3.41.0.0>.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List)'


bk-1.0.4.5
bk-1.1.0.9
bk-2.1.4.3
bk-3.4.1.5
bk-3.41.0.0

Awesome!
-T

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



Re: I need sorting help

2024-03-04 Thread ToddAndMargo via perl6-users

On 3/4/24 23:01, ToddAndMargo via perl6-users wrote:
No I have 


Sould have been
   Now I have




Re: I need sorting help

2024-03-04 Thread ToddAndMargo via perl6-users

On 3/4/24 22:09, Bruce Gray wrote:




On Mar 4, 2024, at 15:55, ToddAndMargo via perl6-users  
wrote:



--snip--


$ raku -e '.say for .sort(*.split(/\d+/, :kv).map({ (try 
.Numeric) // $_}).List)'
bk1
bk2
bk10
bk34

Yippee!


tony@rn6:/home/linuxutil1$ raku -e '.say for .sort: { 
.comb(/ \d+ | \D+ /) .map({ .Int // .self })};'
bk1
bk10
bk2
bk34

Rats!  Thank for trying anyway!

--
love, todd



Wow! Very subtle trap with Seq!

The short answer is: Just add `.cache`:
raku -e '.say for .sort: { .comb(/ \d+ | \D+ /).map({ .Int 
// .self }).cache };'
bk1
bk2
bk10
bk34

When the elements that `.sort` is sorting are of type List or Array, the 
sorting happens one slot at a time; the sort happens on element [0] of each 
List, and ties are settled by [1] (or [2] if [1] are also a tie, etc). This 
enables `.sort` to behave very intuitively (after the shock wears off).

I did not detect the problem by eye, but when I broke it down on the 
commandline I see that Seq objects are being created by `.comb` and `.map`.
Objects of Seq type can only be read *once*, so the multiple reads that `.sort` 
needs would not play well with Seq. It does not matter whether you convert the 
numbers to a Numeric type (which you did correctly in the `.map`), they are 
still part of a Seq.

The .cache method turns the Seq into a List, and the sort behaves as you 
intended.
https://docs.raku.org/routine/cache


Awesome!  No I have two different methods!

-T



Re: I need sorting help

2024-03-04 Thread ToddAndMargo via perl6-users

On 3/4/24 13:55, ToddAndMargo via perl6-users wrote:

On 3/4/24 12:40, Ralph Mellor wrote:

On Sat, Mar 2, 2024 at 6:26 AM ToddAndMargo via perl6-users
 wrote:


@Sorted_List = @Sorted_List.sort: { .comb(/ \d+ | \D+ /) .map({ .Int 
// .self })};


In case another answer is helpful...

First, a simplified sort that produces the same
result as your code above:

@Sorted_List .= sort: *.match: / \d+ /;

I can explain that in a later comment if you want, but it's
all stuff I recall you figuring out in the past, so for now I'll
just move on to address the change you wanted.

The problem you had was that sort defaults to a string sort.
In string sorting 1, 10, 2 are already sorted, but you instead
want numeric order, which sorts those three into 1, 2, 10.

To do that, coerce the sort value to numeric by inserting a `+`:

@Sorted_List .= sort: +*.match: / \d+ /;

--
love, raiph



$ raku -e '.say for .sort(*.split(/\d+/, :kv).map({ 
(try .Numeric) // $_}).List)'

bk1
bk2
bk10
bk34

Yippee!


tony@rn6:/home/linuxutil1$ raku -e '.say for .sort: { 
.comb(/ \d+ | \D+ /) .map({ .Int // .self })};'

bk1
bk10
bk2
bk34

Rats!  Thank for trying anyway!




$ raku -e '.say for .sort: { .comb(/ \d+ | \D+ /) 
.map({ .Str // .self })};'

bk1
bk10
bk2
bk34


Double Rats!


Re: I need sorting help

2024-03-04 Thread ToddAndMargo via perl6-users

On 3/4/24 12:40, Ralph Mellor wrote:

On Sat, Mar 2, 2024 at 6:26 AM ToddAndMargo via perl6-users
 wrote:


@Sorted_List = @Sorted_List.sort: { .comb(/ \d+ | \D+ /) .map({ .Int // .self 
})};


In case another answer is helpful...

First, a simplified sort that produces the same
result as your code above:

@Sorted_List .= sort: *.match: / \d+ /;

I can explain that in a later comment if you want, but it's
all stuff I recall you figuring out in the past, so for now I'll
just move on to address the change you wanted.

The problem you had was that sort defaults to a string sort.
In string sorting 1, 10, 2 are already sorted, but you instead
want numeric order, which sorts those three into 1, 2, 10.

To do that, coerce the sort value to numeric by inserting a `+`:

@Sorted_List .= sort: +*.match: / \d+ /;

--
love, raiph



$ raku -e '.say for .sort(*.split(/\d+/, :kv).map({ 
(try .Numeric) // $_}).List)'

bk1
bk2
bk10
bk34

Yippee!


tony@rn6:/home/linuxutil1$ raku -e '.say for .sort: { 
.comb(/ \d+ | \D+ /) .map({ .Int // .self })};'

bk1
bk10
bk2
bk34

Rats!  Thank for trying anyway!

--
love, todd


Re: missing block

2024-03-03 Thread ToddAndMargo via perl6-users

On 3/3/24 04:25, Elizabeth Mattijsen wrote:

On 3 Mar 2024, at 05:12, ToddAndMargo via perl6-users  
wrote:
$ raku -I./ -c CobianWrapper.pl6
Missing block
at /home/CDs/Windows/NtUtil/CobianWrapper.pl6:1000

1000 is the last line in my code.  I presume by
"block" they mean something like "]" or "}"

Do I really have to read 1000 lines of code to find my screw
up?   Anyone have a tip on how to find it quicker?


I use `vim` as the editor.

In `vim` if I have this situation, then I put the cursor on the first opening { 
 and press `%`.  This brings me to the corresponding closing }.

If the associated closing curly does not match your expectations, then you're 
nearing the source of the problem.

I assume other code editor have a similar `%` functionality.


Hi Elizabeth,

I learned vi about 35 years ago.  I still use
it occasionally.  I will have to try out that
% feature out.  Thank you!   (I just made
a quick "Keeper" out of it.)

I use Geany for programming a lot.  Primarily
as is works well with ssh X11 over poor internet
connections.

Geany has a thing were you park on a bracket of
some type and it will turn the other end blue.
So, something similar to vi (an alias to vim).

To work around the missing block issue, I always
place both sides of a {} before writing inside
them.  It does not always work if I ramble too much.

And it is the tip off that I have rambled on too
much and need to put some things into subs.
Considering I am a YUGE proponent of "top down"
programming, I really should know better.

This is what became of your help:

sub SortList( @List, Str $Msg, Bool $NoDebug )  {
   my @Sorted = Empty;
   @Sorted = @List.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // 
$_}).List);


   if  %Options< Debug >  && not $NoDebug  {
  print "$Msg";
  for @Sorted.kv -> $Index, $Element  {
  print "   Element [$Index]  <$Element>\n";
  }
   }
   return @Sorted;
}


sub ListParentDir( Str $Msg, Bool $NoDebug = False  )  {
   # list and sort %Options
   my @List = Empty;
   for dir( %Options ) { push @List, $_.Str };
   @List = SortList @List, $Msg, $NoDebug;
   return @List;
}


It really cut down on the clutter and made missing
bracket much easier to find.

Oh and you helped me fix a bug in my program that I
had though was a Windows error that had been going
on for years.  Thank you again!

-T





Re: missing block

2024-03-02 Thread ToddAndMargo via perl6-users

On 3/2/24 20:12, ToddAndMargo via perl6-users wrote:

Hi All,

$ raku -I./ -c CobianWrapper.pl6
Missing block
at /home/CDs/Windows/NtUtil/CobianWrapper.pl6:1000

1000 is the last line in my code.  I presume by
"block" they mean something like "]" or "}"

Do I really have to read 1000 lines of code to find my screw
up?   Anyone have a tip on how to find it quicker?

Many thanks,
-T


Found it.  It was a missing "}"

I did it by erasing the innards of the suspected directory
(after making a copy of it of cource), then running -c.
Syntax came back okay.

Then it was a meter of doing he same to blocks inside
the directory until I finally narrowed it down.

Geez!!!

-T



missing block

2024-03-02 Thread ToddAndMargo via perl6-users

Hi All,

$ raku -I./ -c CobianWrapper.pl6
Missing block
at /home/CDs/Windows/NtUtil/CobianWrapper.pl6:1000

1000 is the last line in my code.  I presume by
"block" they mean something like "]" or "}"

Do I really have to read 1000 lines of code to find my screw
up?   Anyone have a tip on how to find it quicker?

Many thanks,
-T


--

Yesterday it worked.
Today it is not working.
Windows is like that.



Re: pint: Elizabeth, sort list???

2024-03-02 Thread ToddAndMargo via perl6-users

On 3/2/24 19:14, Clifton Wood wrote:

.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List)


Can you take apart the above for me?


Re: ping: Elizabeth, sort list???

2024-03-02 Thread ToddAndMargo via perl6-users

Sorry, that was suppose to be "ping: not "pint:


pint: Elizabeth, sort list???

2024-03-02 Thread ToddAndMargo via perl6-users

On 3/2/24 05:13, Elizabeth Mattijsen wrote:

.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List)



Hi Elizabeth,

 It works perfectly.  Thank you!

 I have no idea why, I will ask you in another post


Hi Elizabeth,

Would you take apart your sort piece by piece and explain
each part?

Many thanks,
-T




Re: I need sorting help

2024-03-02 Thread ToddAndMargo via perl6-users

On 3/2/24 05:13, Elizabeth Mattijsen wrote:

.sort(*.split(/\d+/, :kv).map({ (try .Numeric) // $_}).List)


Hi Elizabeth,

 It works perfectly.  Thank you!

 I have no idea why, I will ask you in another post

-T


I need sorting help

2024-03-01 Thread ToddAndMargo via perl6-users

Hi All,

@Sorted_List = @Sorted_List.sort: { .comb(/ \d+ | \D+ /) .map({ .Int // 
.self })};


gives me

   Element [0]  
   Element [1]  
   Element [2]  
   Element [3]  
   Element [4]  
   Element [5]  
   Element [6]  
   Element [7]  
   Element [8]  
   Element [9]  

I need it to say

   Element [0]  
   Element [1]  
   Element [2]  
   Element [3]  
   Element [4]  
   Element [5]  
   Element [6]  
   Element [7]  
   Element [8]  
   Element [9]  

What did I goof up, this time?

Many thanks,
-T


Re: disable coercing?

2024-02-26 Thread ToddAndMargo via perl6-users

On 2/25/24 17:45, Joseph Brenner wrote:

Would this trick help?  You can define a "subset" that restricts
values to the uint16 range:

  my subset FussyUint16 of Int where 0 ..^ 2¹⁶;
  my FussyUint16 $x;
  $x = -1;
  ## Type check failed in assignment to $x; expected FussyUint16
but got Int (-1)


I got around it by cleaning up my act.  It was
really my fault for not respecting what Raku
was trying to do.  Since I endeavor to define
all my variables, I should have known better.


Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users

On 2/12/24 15:04, Will Coleda wrote:



On Mon, Feb 12, 2024 at 5:32 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


On 2/12/24 14:29, ToddAndMargo via perl6-users wrote:
 >>> On Mon, Feb 12, 2024 at 3:24 PM ToddAndMargo via perl6-users
 >>> mailto:perl6-us...@perl.org>
<mailto:perl6-us...@perl.org <mailto:perl6-us...@perl.org>>> wrote:
 >>
 >>>     Has .pl6 been renamed too?
 >
 > On 2/12/24 12:37, Will Coleda wrote:
 >  > Please see: https://docs.raku.org/language/filename-extensions
<https://docs.raku.org/language/filename-extensions>
 >  > <https://docs.raku.org/language/filename-extensions
<https://docs.raku.org/language/filename-extensions>>
 >  >
 >
 > Thank you!  I saved it in my own documentation.

Interesting that the site calls Raku code a
"script".  I wonder just exactly how many
thousands of lines of code I have to write before
I can officially call it a "program"?


Pull requests welcome, and if you have any specific notes about searches 
that aren't working for you, please report them on 
https://github.com/Raku/doc/issues <https://github.com/Raku/doc/issues>.


You can click on the edit icon on that doc page to easily submit a PR.



Hi Will,

Richard wrote me off line that the search had been updated
too, so I gave it the search I bombed out a month or so ago:

https://www.google.com/search?q=site%3Adocs.raku.org+unit32

Forth one down.

int8(int8_t in C)
int16   (int16_t in C)
int32   (int32_t in C)
int64   (int64_t in C)
byte, uint8 (uint8_t in C)
uint16  (uint16_t in C)
uint32  (uint32_t in C)
uint64  (uint64_t in C)
num32   (float in C)
num64   (double in C)

Yippee!

Now to figure out why I was bombing on int32 (DWORD)
[2] > my uint32 $x = 2
2
[3] > my int32 $y = $x.int32

No such method 'int32' for invocant of type 'Int'.  Did you mean 'Int'?
  in block  at  line 1
  in any  at 
/opt/rakudo-pkg/bin/../share/perl6/runtime/perl6.moarvm line 1
  in any  at 
/opt/rakudo-pkg/bin/../share/perl6/runtime/perl6.moarvm line 1



But this works:

[4] > my int32 $y = $x.Int
2

H.

-T


Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users

On 2/12/24 15:04, Will Coleda wrote:
Pull requests welcome, and if you have any specific notes about searches 
that aren't working for you, please report them on 
https://github.com/Raku/doc/issues .


You can click on the edit icon on that doc page to easily submit a PR.


I will check it out!  Thank you!


Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users

On 2/12/24 14:29, ToddAndMargo via perl6-users wrote:
On Mon, Feb 12, 2024 at 3:24 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:



    Has .pl6 been renamed too?


On 2/12/24 12:37, Will Coleda wrote:
 > Please see: https://docs.raku.org/language/filename-extensions
 > <https://docs.raku.org/language/filename-extensions>
 >

Thank you!  I saved it in my own documentation.


Interesting that the site calls Raku code a
"script".  I wonder just exactly how many
thousands of lines of code I have to write before
I can officially call it a "program"?



Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users
On Mon, Feb 12, 2024 at 3:24 PM ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:



Has .pl6 been renamed too?


On 2/12/24 12:37, Will Coleda wrote:
> Please see: https://docs.raku.org/language/filename-extensions
> <https://docs.raku.org/language/filename-extensions>
>

Thank you!  I saved it in my own documentation.

I can't find a thing anymore since they updated the
documentation site.  I use google a lot and my own
documentation.  Looking up "raku" gets me a ton of hits
on Japanese pottery, so it is frustrating.


Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users




On 12 Feb 2024, at 20:34, ToddAndMargo via perl6-users  
wrote:



On 6 Feb 2024, at 18:08, ToddAndMargo via perl6-users  
wrote:

Hi All,

I use AnyDesk for remoter customer support.  Work rather well.

The file transfer portion, which I adore, posts a Microsoft
Office Publisher Icon (a big one) when it hits a .pm6 modules.

Is there a different naming convention I can use for my
modules that does not mimic some other program?

Many thanks,
-T


On 2/12/24 11:11, Elizabeth Mattijsen wrote:

.rakumod



Thank you!

Is there a way to get raku to ignore pm (perl 5)
module naming?


On 2/12/24 11:40, Elizabeth Mattijsen wrote:
> It's been marked as DEPRECATED since 2023.12 I believe.
>

Cool.

Has .pl6 been renamed too?



Re: pm6 naming convention

2024-02-12 Thread ToddAndMargo via perl6-users




On 6 Feb 2024, at 18:08, ToddAndMargo via perl6-users  
wrote:

Hi All,

I use AnyDesk for remoter customer support.  Work rather well.

The file transfer portion, which I adore, posts a Microsoft
Office Publisher Icon (a big one) when it hits a .pm6 modules.

Is there a different naming convention I can use for my
modules that does not mimic some other program?

Many thanks,
-T


On 2/12/24 11:11, Elizabeth Mattijsen wrote:
> .rakumod


Thank you!

Is there a way to get raku to ignore pm (perl 5)
module naming?



Re: who call raku?

2024-02-10 Thread ToddAndMargo via perl6-users

On 2/10/24 16:01, ToddAndMargo via perl6-users wrote:

On 2/10/24 15:26, Marc Chantreux wrote:
On Thu, Feb 08, 2024 at 02:25:00PM -0800, ToddAndMargo via perl6-users 
wrote:

Actually, I am looking for the name of the calling program:
Cobian, Task manager, deamon, etc..


linux centric anwser:

raku -e 'say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]'

hth




$ raku -e 'say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]'
bash


Very cool.  Thank you.

I also need (only a little bit, I figured a way
around it) to kow how to do it in Windows.




Winsdows no so cool.  perl -e does not get past the
quoting issue from the command console.

So:

>raku

[0] > say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]
Failed to open file K:\proc\6640\stat: No such file or directory
  in method throw at 'SETTING::'src/core.c/Exception.rakumod line 65
  in method fail at 'SETTING::'src/core.c/Exception.rakumod line 89
  in block  at 'SETTING::'src/core.c/IO/Handle.rakumod line 158
  in method open at 'SETTING::'src/core.c/IO/Handle.rakumod line 155
  in method open at 'SETTING::'src/core.c/IO/Path.rakumod line 212
  in method words at 'SETTING::'src/core.c/IO/Path.rakumod line 805
  in block  at  line 1



Re: who call raku?

2024-02-10 Thread ToddAndMargo via perl6-users

On 2/10/24 15:26, Marc Chantreux wrote:

On Thu, Feb 08, 2024 at 02:25:00PM -0800, ToddAndMargo via perl6-users wrote:

Actually, I am looking for the name of the calling program:
Cobian, Task manager, deamon, etc..


linux centric anwser:

raku -e 'say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]'

hth




$ raku -e 'say "/proc/{"/proc/$*PID/stat".IO.words[3]}/comm".IO.lines[0]'
bash


Very cool.  Thank you.

I also need (only a little bit, I figured a way
around it) to kow how to do it in Windows.


Re: disable coercing?

2024-02-10 Thread ToddAndMargo via perl6-users

On 2/10/24 02:41, Elizabeth Mattijsen wrote:

On 10 Feb 2024, at 08:56, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a switch to tell Raku to bomb out with a
type mismatch rather than coercing the following?


my uint16 $x = -1

65535


No, this is intentional behaviour on native integers.


Rats.

I type cast my variable when I can to keep me out of trouble
("Expected Int but got Str").  Guess I got a bit too
lazy.   I am going to have to be more careful when
dealing with Cardinals (unit's).  I did get stung by this
yesterday. Took me hours to figure it out.


Note that you can increment such a value without problems:

[0] > my uint16 $x = -1;
65535
[1] > ++$x
0


Oh now that is really sneaky and speaks
of any underlying understand of bit wise
operations!  :-)

Thank you!




disable coercing?

2024-02-09 Thread ToddAndMargo via perl6-users

Hi All,

Is there a switch to tell Raku to bomb out with a
type mismatch rather than coercing the following?

> my uint16 $x = -1
65535


Many thanks,
-T


--

If I had a dime every time I didn't know
what was going on, I'd be like, "Why is
everyone giving me all these dimes?"



Re: who call raku?

2024-02-08 Thread ToddAndMargo via perl6-users

On 2/8/24 14:25, ToddAndMargo via perl6-users wrote:

On 2/8/24 13:19, Bruce Gray wrote:



On Feb 8, 2024, at 15:12, ToddAndMargo via perl6-users 
 wrote:


Hi All,

Is there one of those fancy system variables that will
tell me who called/started raku?


Ooops.  I should have said "what called" not "who called".


raku -e 'say $*USER'
bruce




Actually, I am looking for the name of the calling program:
Cobian, Task manager, deamon, etc..


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



Re: Session ID

2024-02-08 Thread ToddAndMargo via perl6-users

On 2/6/24 17:50, ToddAndMargo via perl6-users wrote:

Hi All

Windows 10 and 11

Does Raku have a system call that will tell
me my "session ID"?

Many thanks,
-T



So far what I have come up with is a system call to "wmic":

>raku -e "sleep 14"

>wmic process where "name='raku.exe'" get ProcessID,SessionID,CommandLine
CommandLine  ProcessId  SessionId
raku  -e "sleep 14"  5020   1


Re: who call raku?

2024-02-08 Thread ToddAndMargo via perl6-users

On 2/8/24 13:19, Bruce Gray wrote:




On Feb 8, 2024, at 15:12, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there one of those fancy system variables that will
tell me who called/started raku?


raku -e 'say $*USER'
bruce




Actually, I am looking for the name of the calling program:
Cobian, Task manager, deamon, etc..


who call raku?

2024-02-08 Thread ToddAndMargo via perl6-users

Hi All,

Is there one of those fancy system variables that will
tell me who called/started raku?


Many thanks,
-T

--
~~~
Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
~~~


Session ID

2024-02-06 Thread ToddAndMargo via perl6-users

Hi All

Windows 10 and 11

Does Raku have a system call that will tell
me my "session ID"?

Many thanks,
-T

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


Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users

On 2/6/24 09:03, Bruce Gray wrote:




On Feb 6, 2024, at 10:52, ToddAndMargo via perl6-users  
wrote:


On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:

$ raku -c foo.rakumod
Syntax OK



$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


The wrapper program can be a `-e` one-liner, like:
 raku -c -e 'use NativeCall;'
 Syntax OK
 
Does this work for you?

 raku -c -e 'use WinMessageBox;'
 


Rats!

$ raku -c -e 'use WinMessageBox;'
===SORRY!=== Error while compiling -e
Could not find WinMessageBox in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<2965876076768>
CompUnit::Repository::NQP<2965910068576>
CompUnit::Repository::Perl5<2965910068616>
at -e:1

$ raku -I./ -c WinMessageBox.pm6
Syntax OK


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



pm6 naming convention

2024-02-06 Thread ToddAndMargo via perl6-users

Hi All,

I use AnyDesk for remoter customer support.  Work rather well.

The file transfer portion, which I adore, posts a Microsoft
Office Publisher Icon (a big one) when it hits a .pm6 modules.

Is there a different naming convention I can use for my
modules that does not mimic some other program?

Many thanks,
-T

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


Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users




On 6 Feb 2024, at 17:52, ToddAndMargo via perl6-users  
wrote:


On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:

$ raku -c foo.rakumod
Syntax OK



$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling /home/CDs/Windows/NtUtil/WinMessageBox.pm6
Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


On 2/6/24 08:57, Elizabeth Mattijsen wrote:
> Do you have some "use lib 'foo'" setting in your program?
>
> If so, use that on the command-line, e.g.:
>
>  $ raku -Ifoo -c bar.rakumod
>

Indeed I do.  Will the above command check those
modules too, or just verify that they are there?





Re: -c question

2024-02-06 Thread ToddAndMargo via perl6-users

On 6 Feb 2024, at 00:39, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T


On 2/6/24 01:34, Elizabeth Mattijsen wrote:
> $ raku -c foo.rakumod
> Syntax OK
>

$ raku -c WinMessageBox.pm6
===SORRY!=== Error while compiling 
/home/CDs/Windows/NtUtil/WinMessageBox.pm6

Could not find NativeConvert in:
/home/tony/.raku
/opt/rakudo-pkg/share/perl6/site
/opt/rakudo-pkg/share/perl6/vendor
/opt/rakudo-pkg/share/perl6/core
CompUnit::Repository::AbsolutePath<4639587332824>
CompUnit::Repository::NQP<4639586267208>
CompUnit::Repository::Perl5<4639586267248>
at /home/CDs/Windows/NtUtil/WinMessageBox.pm6:50

$ which NativeConvert.pm6
./NativeConvert.pm6
and three other pm.6's WinMessageBox imports.

I can only compile check my modules if I
import them to a program and -c the program.

For example, the following program uses
the above module:
$ raku -c CobianWrapper.pl6
Syntax OK

I just want to do a syntax check on my modules
at time without the program.

:'(


-c question

2024-02-05 Thread ToddAndMargo via perl6-users

Hi All,

Is there a way to syntax a module?  Sort of like the "-c"
option on main programs?

Many thanks,
-T



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


Re: run on regex line?

2024-01-20 Thread ToddAndMargo via perl6-users

On 1/20/24 01:42, William Michels via perl6-users wrote:


On Jan 19, 2024, at 23:49, ToddAndMargo via perl6-users 
 wrote:


Hi All,

Can I do a run on line with a regex like I
just did with sed?

$ zbarimg Screenshot.png | sed -e 's/.*?secret=//' -e 's/&.*//'

Usually I just do two lines in Raku.

Many thanks,
-T



Hi Todd,

Not that I am aware. The naive way is just to pipe them:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/' | raku -pe 
's/red/blue/'

lilacs are blue


The Raku way would be combining those two statements into one Raku call:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/; s/red/blue/'
lilacs are blue



I like this one! It is easy to figure out at a glance.



#OR ("big-S" notation below)

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/ andthen S/red/blue/.put'
lilacs are blue


The `andthen` call reloads the `$_` topic variable. For more examples, see:

https://stackoverflow.com/questions/65066358/concatenating-s-in-raku 
<https://stackoverflow.com/questions/65066358/concatenating-s-in-raku>


HTH, Bill


It does.  Thank you!

Raku's regex's spoil me.  sed has to be
the editor from ...

Then again, I still use vi at times.


run on regex line?

2024-01-19 Thread ToddAndMargo via perl6-users

Hi All,

Can I do a run on line with a regex like I
just did with sed?

$ zbarimg Screenshot.png | sed -e 's/.*?secret=//' -e 's/&.*//'

Usually I just do two lines in Raku.

Many thanks,
-T




Re: optimizer?

2024-01-07 Thread ToddAndMargo via perl6-users

On 1/7/24 15:18, ToddAndMargo via perl6-users wrote:
sub DirectoryExists( Str $DirPath --> Bool ) { return 
"$DirPath".IO.d.Bool; }  # $Full DirPath format is `H:\MyDocsBackup`


Problem:  sometimes DirectoryExists lies about
backup1 existing.




Here is what I am up against.

You will note the "junction" points.  They should not be backed up.
But they are an being creasted as simple directories.

C:\Users\accounting\Documents>dir /a | grep -i junction
09/14/2020  07:39 AM My Music [C:\Users\accounting\Music]
09/14/2020  07:39 AM My Pictures 
[C:\Users\accounting\Pictures]
09/14/2020  07:39 AM My Videos 
[C:\Users\accounting\Videos]



This is the backup directory after a Windows Explorter erase.
Both DirectoryExists ($DirPath".IO.d.Bool" and Windows
Explorer with Hidden file turned on says it does not exist.

You will note that the command line says it does indeed exist.
And it does.

F:\MyDocsBackup\backup3\Documents 2023-08-15 16;28;47 (Full)>dir /a
 Volume in drive F is BACKUP
 Volume Serial Number is 0866-7D92

 Directory of F:\MyDocsBackup\backup3\Documents 2023-08-15 16;28;47 (Full)

01/05/2024  07:49 PM  .
01/05/2024  07:49 PM  ..
08/15/2023  03:29 PM  My Music
08/15/2023  03:29 PM  My Pictures
08/15/2023  03:29 PM  My Videos
   0 File(s)  0 bytes
   5 Dir(s)  480,294,719,488 bytes free

Windows is such a horrid kluge.

:-(

-T




Re: optimizer?

2024-01-07 Thread ToddAndMargo via perl6-users

On 1/7/24 06:16, Parrot Raiser wrote:

What's the reason behind the request?


Hi Parrot,

The reason is to eliminate the Optimizer as a
source of weird problems.

I have written a wrapper for Cobian Backup/Reflector
that rotates backup sets.  Cobain has is own database
to keep track of backup sets, but it falls apart when
you are rotating several removable drives as the target.

Removable drives in rotation defeats ransomware.

So, my program locates the drive letter the target
resides on based on drive label (it will do letter too),
then counts the backup sets.  If these sets exceed
the limit of sets, I remove the oldest.

For example maximum backup sets is set to 4.  Then backup4
gets erased, backup3 gets renamed to backup4, backup2
gets renamed to backup3, backup1 gets renamed to backup2.

At this point there should be no backup1.  And I check for
it:

sub DirectoryExists( Str $DirPath --> Bool ) { return 
"$DirPath".IO.d.Bool; }  # $Full DirPath format is `H:\MyDocsBackup`


Problem:  sometimes DirectoryExists lies about
backup1 existing.  Failure to rotate has to do with
something is the backup set that won't move.  These
are typically system files.  When I find them, I enter
into Cobian's exclude mask:

desktop.ini
Thumbs.db
.dropbox.*
.dropbox.cache
sessions.jsoniz4
events
~*
~$
python.exe
python3.exe


I have traced this down to the "size" of backup1 too.
A directory in backup1 that refuses to move in
a large backups, will move in a simple test task.

Now to workaround the issue of DirectoryExists not
always returning the correct answer, I have written
my own code for it:

sub IsItReallyReallyGone( Str $Path --> Bool ) {
# checks to see if a file or directory is really gone and not stuck in cache
   my Bool $Gone = False;
   my Str $RtnStr = "";

   # Note: "File Not Found" is sent to the STDERR
   $RtnStr  = RunCmd Q[dir ] ~ $Path ~ Q[ /A  2>&1];
   if $RtnStr.lc.contains( "file not found" )  { $Gone = True ; }

   # if %CommandLine  { print "   IsItReallyReallyGone:\n   Gone 
= <$Gone>\n   Path = <$Path>\n   RtnStr = <$RtnStr>\n"; }
   if %CommandLine  { print "   IsItReallyReallyGone: $Path is 
$Gone\n"; }


   return $Gone;
}


And I flush a lot(same as Linux's "sync"):

sub FlushDriveCache( Str $Drive )  {
   my Str $SingleLetter = $Drive.uc.substr( 0..0 );
   my Str $RtnStr   = "";

   print "   Flushing " ~ $SingleLetter ~ "'s drive cache\n";
   $RtnStr = RunCmd "powershell.exe Write-VolumeCache " ~ 
$SingleLetter, True;

}


And IsItReallyReallyGone is dead nuts totally, repeatable accurate.
If backup1 is really not gone, a flush and a second delete usually
does the trick.  (I can repeat this double erase with Windows
Explorer.  First time through it coughs on certain files.
Second time through, it gets them all.)

sub FastRmdir( $DirPath )  {
   RunCmd( "del /f/s/q " ~ $DirPath ~ " > nul" );
   RunCmd( "rmdir " ~ $DirPath ~ " /S /Q" );
}


Now if backup1 still exists and is not rotated, Cobian keeps
writing to it and eventually the target drive fill up,
meaning no more new backups.

And that is a problem, especially with trying to get my
customer's to actually read their backup reports that
Cobian eMails them (and me, but I only check them
periodically and only as a courtesy).

So in summary, the issue is probably a cache issue with
Raku's IO commands not keeping up with what Windows
is doing.  Disabling the Optimizer would remove that
issues as a problem.  And Raku's IO commands needs
some work when dealing with large amounts of a data
in cache.

Sorry for being so long winded.

-T

My program's help file:

>raku CobianWrapper.pl6 --help
Welcome to CobianWrapper.pl6

CobianWrapper.pl6 usage:

  CobianWrapper.pl6
--backup_path 
 Drive letter or partition label plus path to backup directory.
 for a label, surround the label with square brackets [].
 Note: the backup directory name must end in a 1
--rotates 
--nokill
 nokill will disable the killing of programs known to be
 Shadow Copy (VSS) unfriendly
--debug
--help

Defaults:
  --backup_path  [BACKUP]\MyDocsBackup\backup1
  --rotates  2
  --nokill   False
  --debugFalse
  --help False

For example
raku C:\NtUtil\CobianWrapper.pl6 --rotates 6 --backup_path 
A:\MyDocsBackup\n\backup1
raku C:\NtUtil\CobianWrapper.pl6 --rotates 4 --backup_path 
[BACKUP]\MyDocsBackup\backup1


more? (y/n)  y

Sample Cobian Pre-backup Event call to CobianWrapper.pl6:

Note: Events, Command Line is currently not working Cobian Reflector as 
of 1.0.0


Execute and wait: "C:\Program Files\Rakudo\bin\raku.exe" 
"C:\NtUtil\CobianWrapper.pl6 --rotates 20 --backup_path 
[BACKUP]\MyDocsBackup\backup1"


Sample Cobian File, Destination for use with CobianWrapper.pl6:
%DISKLABEL="BACKUP":\MyDocsBackup\backup1

Sample Cobian Post-backup Event call to CobianWrapper.pl6 (requires 
USB_Disk_Eject-1.3.0.3.exe):

Execute 

Re: optimizer?

2024-01-07 Thread ToddAndMargo via perl6-users




On 7 Jan 2024, at 07:09, ToddAndMargo via perl6-users  
wrote:

Hi All,

Is there a switch on the command line to disable the code optimizer?

Many thanks,
-T


On 1/7/24 04:24, Elizabeth Mattijsen wrote:
> $ raku --help
>
> ...
> --optimize=level use the given level of optimization (0..3)
> ...
>

Thank you!





optimizer?

2024-01-06 Thread ToddAndMargo via perl6-users

Hi All,

Is there a switch on the command line to disable the code optimizer?

Many thanks,
-T


Re: initializing Pointer

2023-12-23 Thread ToddAndMargo via perl6-users

On 12/23/23 00:21, Marcel Timmerman wrote:
(perhaps already received but I'd got an error back saying '*Delivery 
has failed to these recipients or groups*' from.outl...@ifdog.com, So 
here it comes again.)





Thanks Elizabeth and Todd;


You are most welcome.



I will set up my own pointer routine, something like this

method make-pointer ( $type, $value ) {
   my $array = CArray[$type].new($value);
   nativecast( Pointer[$type], $array)
}

I forgot the way to make the method type depended and how to search for 
it in the docs.


Regards,
Marcel


Came through on both attempts at this end.

-T


Re: initializing Pointer

2023-12-20 Thread ToddAndMargo via perl6-users

On 12/20/23 11:12, Marcel Timmerman wrote:

Hi,

I would like to initialize a Pointer with some value but get an error. 
For example;


my $a = Pointer[Str].new('text');

The error thrown:

Default constructor for 'NativeCall::Types::Pointer[Str]' only takes 
named arguments


The way I can do it now is by creating a CArray and then do a nativecast 
which is a bit cumbersome.
The reason I would like to use Pointers is when there is only one object 
to point to, not an array. Secondly, for the use of the deref() function 
to get the value it points to.


Is there another way to solve this or is it a bug in the 
NativeCall::Types module. I have noticed that there  are 3 new() methods 
defined accepting positional arguments.


Regards,
Marcel


Hi Marcel,

I always initialize a pointer with a binary zero.  This is
a null pointer in C.  A "DWORD" is a 32 bit unsigned integer.

Here is some code of mine to work with Windows error messages.
Maybe there is something in it that will give you some examples.
Unfortunately, I did this years ago and have forgotten most of
how I did it.

Note.  Anything that starts with "LP" is a (LONG or 32 bit
not 64 bit -- it'sa Windows thing) pointer.  For example
"LPCWSTR lpSubKey".

Also note that C string are terminated with a nul.  Or
in the case of UTF-16, two nuls.  This is not the case in
Raku as a Raku string comes with a hidden structure
that tells you the length of the string, meaning a
Raku string can contain nuls.

You will see me doing

   my BYTES  $lpBuffer = CArray[BYTE].new( 0xFF xx $nSize );

in places.  This is to help me troubleshoot.  You will
get back "blah blah blah null 0xFF 0xFF ..."

HTH,
-T


constant NULL = 0x;
sub WinFormatMessage( uint32 $ErrorNumber, Bool $Debug = False ) returns 
Str is export( :WinFormatMessage ) {



#`{

 Return a string with the error message corresponding to the error 
number



https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-formatmessagew


 DWORD FormatMessageW(
 DWORD   dwFlags,  # bitwise OR 
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_IGNORE_INSERTS
 LPCVOID lpSource, # NULL.  The location of the message 
definition. The type of this parameter depends upon the settings in the 
dwFlags parameter.

 DWORD   dwMessageId,  # the error message number ($ErrorNumber)
 DWORD   dwLanguageId, # 0 for system's language
 LPTSTR  lpBuffer, # the return string, give it 1024
 DWORD   nSize,# 0  nubmer of bytes in the return
 va_list *Arguments# NULL
 );

https://social.msdn.microsoft.com/Forums/vstudio/en-US/8f0eed1f-a180-4a08-bda9-3dc61e4fdd02/what-is-the-function-to-turn-an-error-number-into-an-error-message?forum=vcgeneral
RLWA comments:  Don't worry about the va_list* parameter in the 
FormatMessageA or
FormatMessageW functions.  Pass NULL and make 
sure to specify
FORMAT_MESSAGE_IGNORE_INSERTS in the dwFlags 
parameter


Note: "LPTSTR is a [long] pointer to a (non-const) TCHAR string"
   LPTSTR: null-terminated string of TCHAR (Long Pointer)

 R. Wieser's declaration:
 DWORD   dwFlags,   // FORMAT_MESSAGE_FROM_SYSTEM 
or FORMAT_MESSAGE_IGNORE_INSERTS

 LPCVOID lpSource,  // 0
 DWORD   dwMessageId,  // The error code
 DWORD   dwLanguageId, // 0
 LPWSTR  lpBuffer,// RW ptr to the string buffer
 DWORD   nSize,   // RW ptr to variable holding 
available string buffer size

 va_list *Arguments // null

}

   my Str $SubName = &?ROUTINE.name;
   my Str $OS  = $*KERNEL.name;
   if not $OS eq "win32" {
  say "Sorry, $SubName only work in Windows.";
  exit; }

   my DWORD  $dwFlags  = FORMAT_MESSAGE_FROM_SYSTEM +| 
FORMAT_MESSAGE_IGNORE_INSERTS;

   my DWORD  $lpSource = NULL;
   my DWORD  $dwMessageId  = $ErrorNumber;   # error number from the 
calling function
   my DWORD  $dwLanguageId = LANG_USER_DEFAULT;   # 0 is the delault 
system language


   my DWORD  $nSize= 1024;  # number of bytes in $lpBuffer, maybe
   # my BYTES  $lpBuffer = CArray[BYTE].new( 0 xx $nSize );
   my BYTES  $lpBuffer = CArray[BYTE].new( 0xFF xx $nSize );
   my DWORD  $va_list  = NULL;
   my Str$ErrorString  = "";
   my DWORD  $RtnCode  = 0;
   my DWORD  $LastError= 0;


   sub FormatMessageW( DWORD, DWORD, DWORD, DWORD, CArray[BYTE] is rw, 
DWORD is rw, DWORD )

  is native("Kernel32")
  is symbol("FormatMessageW")
  returns DWORD
   { * };

   $RtnCode = FormatMessageW( $dwFlags, $lpSource, $dwMessageId, 
$dwLanguageId, $lpBuffer, $nSize, $va_list );


   # say "$lpBuffer";
   # say $lpBuffer[ 0 ];
   # say $lpBuffer[ 0 ] +| 0x00;
   if not $lpBuffer[ 0 ] == -1  {# -1 = 0xFF (it gets coersed) 
means nothing was returned

  

Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

This is from my keeper on "match".  It is the Perl 5 way
of explaining things.  It works really well for me.

How did I do?



To find a match of "any" of the following

my $x="abc2def"; say so $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / )
my $x="abc2def"; say so $x.match( / ^ <+[0..9] + [a..z]> ** {$x.chars} $ / )
True

Explanation of the above:
   This is the "match" usage of "regex".

   The test starts from the beginning of the string and ends
   at the end of the string.  It asks each cell in the string
   if contains one of characters taken from the set of
   characters including the digits "0"-through-"9" and
   the lowercase letters "a"-through-"z".

  $x is the string to test

  `so` removed the individual results of each cell in $x and
  just return a single True or False

  `.match()` is the test command (method) applied by the regex
  to $x.  The `()` is required.  And you have to spell out ".match"

   The `/` at the beginning and end are the constraints of
   the regex.   Note that there are only two of them, not three
   as with a substitution regex (~~s/xx/y/)

  `^` means to start testing at the beginning of $x

  `<[0..9]> + [a..z]>` are the range of alpha numeric characters
  (not numbers) to test for in each $x cell.  In this case, the
  the lowercase letters "a"-through-"z" and the digits "0"-through-"9".
  (Note: string character that look like numbers and not binary
  number, but ASCII repersention of numbers)

  `** 8` and ** `{$x.chars}` are the length of $x.  If you "goof"
  the length of $x (larger or smaller), regex will return a Nil.
  `{$x.chars}` will avoid this.

  `$` means to stop testing at the end of $x




Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 16:11, William Michels via perl6-users wrote:



On Dec 11, 2023, at 15:54, ToddAndMargo via perl6-users 
 wrote:


On 12/11/23 15:48, William Michels via perl6-users wrote:
On Dec 10, 2023, at 23:22, ToddAndMargo via perl6-users 
 wrote:




Is there a list somewhere of all the shortcuts, such as "alnum"?
--


https://docs.raku.org/language/regexes#Regexes 
<https://docs.raku.org/language/regexes#Regexes>


https://docs.raku.org/language/regexes#Predefined_character_classes 
<https://docs.raku.org/language/regexes#Predefined_character_classes>


HTH, Bill.


:-)  :-)  :-)


Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 15:48, William Michels via perl6-users wrote:



On Dec 10, 2023, at 23:22, ToddAndMargo via perl6-users 
 wrote:


On 12/10/23 22:26, William Michels via perl6-users wrote:

Hi Bill,
Yes it does help.  I am slowly getting there.

If I do not know the length of the sting and have to ask
with .chars, is there a way to use a variable in `** 7`

** $x.chars   or
my $xlen = $x.chars; `** $xlen`

or some such?  Is there a special syntax?
Also, must the `**7`  (does it have a name?) always be the length
of the string?
Also, if I do not use ^ and $, what happens?

Yours in confusion,
-T



In the Raku REPL (MoarVM 2023.05):

[3] > my $x="abc2def"; put $x.match: / ^  ** 7 $ /;
abc2def
[3] > my $x="abc2def"; put so $x.match: / ^  ** 7 $ /;
True
[3] > my $x="abc2def"; put $x.match: / ^  ** {$x.chars} $ /;
abc2def
[3] > my $x="abc2def"; put $x.match: / ^  ** {$x.chars + 1} $ /;
Use of Nil in string context
   in block  at  line 1


[3] > my $x="abc2def"; say $x.match: / ^  ** {$x.chars + 1} $ /;
Nil
[3] > my $x="abc2def"; say $x.match: / ^  ** {$x.chars} $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」
[3] > my $x="abc2def"; say so $x.match: / ^  ** {$x.chars} $ /;
True
[3] > my $x="abc2def"; say so $x.match: / ^  ** {$x.chars + 1} $ /;
False
[3] >

HTH, Bill.


Is there a list somewhere of all the shortcuts, such as "alnum"?
--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~



Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 15:48, William Michels via perl6-users wrote:



On Dec 10, 2023, at 23:22, ToddAndMargo via perl6-users 
 wrote:


On 12/10/23 22:26, William Michels via perl6-users wrote:

Hi Bill,
Yes it does help.  I am slowly getting there.

If I do not know the length of the sting and have to ask
with .chars, is there a way to use a variable in `** 7`

** $x.chars   or
my $xlen = $x.chars; `** $xlen`

or some such?  Is there a special syntax?
Also, must the `**7`  (does it have a name?) always be the length
of the string?
Also, if I do not use ^ and $, what happens?

Yours in confusion,
-T



In the Raku REPL (MoarVM 2023.05):

[3] > my $x="abc2def"; put $x.match: / ^  ** 7 $ /;
abc2def
[3] > my $x="abc2def"; put so $x.match: / ^  ** 7 $ /;
True
[3] > my $x="abc2def"; put $x.match: / ^  ** {$x.chars} $ /;
abc2def
[3] > my $x="abc2def"; put $x.match: / ^  ** {$x.chars + 1} $ /;
Use of Nil in string context
   in block  at  line 1


[3] > my $x="abc2def"; say $x.match: / ^  ** {$x.chars + 1} $ /;
Nil
[3] > my $x="abc2def"; say $x.match: / ^  ** {$x.chars} $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」
[3] > my $x="abc2def"; say so $x.match: / ^  ** {$x.chars} $ /;
True
[3] > my $x="abc2def"; say so $x.match: / ^  ** {$x.chars + 1} $ /;
False
[3] >

HTH, Bill.


Awesome!   Thank you!

I am going to steal your examples for my keeper!




Re: .contains question

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 14:47, Andy Bach wrote:

 I have found that when using `say` for debugging, it has been known to print 
out the
previous value of a variable and not the current value.  `print` does not do 
this.


That would certainly be a surprise to me. I'd think I was 
misunderstanding my program, rather than a bug in say.


Hi Andy,

1) I can not duplicate the issue in a small program

2) I did a `say ($x)` on top of a `print "$x\n"`
and got two different answers.  The `say` was the
previous value of the variable.  (It about drove
me crazy trying to figure out what was going on.)

I have had this happen several times in my large programs.
This makes me think it is an issue in the code optimizer.
And it may very well be fixed now.

In my Modula 2 days, I had to turn off the code optimizer
as these issues were crazy making.  So I did recognize the
problem.  So far, the only instance of  optimizer
problems I have found in Raku has been with `say`.  And
it is easily worked around.  Raku itself is very well done
and is fun to program in.

If you have read any of my code, you know I have written
print modules to write out in color and to write out to
the STDERR: black, blue, green, red.  I have been thinking
of writing a `println`, but it would not be all that useful
as I am always up to something at the end of the line.

-T


Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 13:39, ToddAndMargo via perl6-users wrote:

On 12/11/23 00:55, Kevin Pye wrote:

Seriously Todd? "What is a digit?" The characters '0' to '9' are digits.
  (Unicode probably has a whole lot of others, but those will do for the
moment.)


Yes seriously.  Does '9' have the ascii value of 57 or the
binary value of 9?  Or do you mean a single character?
Would 'a' also be a digit?  Or are digits limited to
ascii 48 to 57 or binary 0 to 9?


Maybe this will make more sense to my question:

[0] > say chr(57)
9

[0] > say ord("9")
57

I am dealing with a string, which is a collection of
characters.  `"9"` in not a number.  It is a character
(ascii 57) that "looks" like a number to the human eye.
This is why I wanted to know what you meant by "digit".


Re: Test not working so well

2023-12-11 Thread ToddAndMargo via perl6-users

On 12/11/23 00:55, Kevin Pye wrote:

Seriously Todd? "What is a digit?" The characters '0' to '9' are digits.
  (Unicode probably has a whole lot of others, but those will do for the
moment.)


Yes seriously.  Does '9' have the ascii value of 57 or the
binary value of 9?  Or do you mean a single character?
Would 'a' also be a digit?  Or are digits limited to
ascii 48 to 57 or binary 0 to 9?

I am saving the rest of your letter to read over very slowly.

Thank you!


Re: .contains question

2023-12-11 Thread ToddAndMargo via perl6-users




"so" will collapse the junction into a Bool.
"say" will append a \n for you, so you don't have to.


On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users  
wrote:


On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users  
wrote:

Hi All,

my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; } else { 
print "False\n" };
True

Is there a way to tell .contains that you want to know
if any of a sequence characters is in a string other that
repeating || over and over.  Any [a..z] or [0..9] option?

Many thanks,
-T


On 12/10/23 15:24, Elizabeth Mattijsen wrote:

my @letters = ;
if $x.contains(any @letters) {



Hi Elizabeth,

Very interesting.  Problem: I was looking for one answer, not many


my $x="abc45def";my @y=; print $x.contains(any @y) ~ 
"\n";

True
True
True
True
True
True
False
False
False
False
False
False
False
True
True


On 12/11/23 01:11, Elizabeth Mattijsen wrote:
> my $x="abc45def";
> my @y=; say so $x.contains(any @y);

Hi Elizabeth,

Awesome!  Thank you!

I usually stay away from `say` as in my longer programs, I have found 
that when using `say` for debugging, it has been known to print out the 
previous value of a variable and not the current value.  `print` does 
not do this.  This is why you see me using `print` so often.  And
I can type, so the extra finger motions do not bother me.  Capitol 
letter also do not for the same reason.


Some tests!

my $x="abc45def"; my @y=; say so 
$x.contains(any @y);

True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False

my $x="abc45def"; my @y=; say so $x.contains(any @y);
True

my $x="abc45def"; my @y=; say so $x.contains(any @y);
False


Oh now I am really pushing it with these (note the `all` in the
second one)!


my $x="abc45def"; say so $x.contains(any );

my $x="abc45def"; say so $x.contains(all );
False

my $x="abc45def"; say so $x.contains(any );
True


-T






Re: Test not working so well

2023-12-10 Thread ToddAndMargo via perl6-users

On 12/10/23 22:26, William Michels via perl6-users wrote:

Inline:

On Dec 10, 2023, at 12:25, ToddAndMargo via perl6-users 
 wrote:


On 12/9/23 22:49, William Michels via perl6-users wrote:

f $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / ) { do something...};



What is the difference between

   <+[0..9]
and
  <[0..9]



Nothing, atm (although there may have been an issue with earlier 
iterations of Rakudo). Anyway, I find it better to be explicit.


See:

https://docs.raku.org/language/regexes#Enumerated_character_classes_and_ranges 
<https://docs.raku.org/language/regexes#Enumerated_character_classes_and_ranges>

https://docs.raku.org/syntax/%3C%5B%20%5D%3E 
<https://docs.raku.org/syntax/%3C%5B%20%5D%3E>




And
   / ^ <+[0..9] + [a..z]> ** 7 $ /

does this mean that both [0..9] AND [a..z] have to
be present.  In other words is the an AND or an OR?



See Kevin Pye's answer. Basically your regex is asking "Starting from 
the beginning of the string and ending at the end of the string, does 
the string consist of exactly 7 characters taken from the set of 
characters including the digits "0"-through-"9" and the lowercase 
letters "a"-through-"z"? If you satisfy those constraints you're okay 
(`True`). You could match a string where 1) all 7 characters are digits, 
2) all 7 characters are lowercase letters, or 3) a mix of digits and 
lowercase letters adding up to 7 characters in length.


HTH, Bill.



Hi Bill,

Yes it does help.  I am slowly getting there.

If I do not know the length of the sting and have to ask
with .chars, is there a way to use a variable in `** 7`

 ** $x.chars   or
 my $xlen = $x.chars; `** $xlen`

or some such?  Is there a special syntax?

Also, must the `**7`  (does it have a name?) always be the length
of the string?

Also, if I do not use ^ and $, what happens?

Yours in confusion,
-T




Re: Test not working so well

2023-12-10 Thread ToddAndMargo via perl6-users

On 12/10/23 19:52, Kevin Pye wrote:



On Mon, 11 Dec 2023, at 09:24, ToddAndMargo via perl6-users wrote:

On 12/10/23 14:16, Kevin Pye wrote:



Because you asked for a match with a string consisting entirely of exactly 8 
digits.



I am not following.  :'(


^beginning of string

<[0..9]> a digit


What do you mean "a digit".  This is not the index of the string?

I though I was testing for the characters "0" (char 48)
through "9" (char 57), not the numbers 0 through 9.



** 8 repeated exactly eight times

% end of string


What does the $ mean


so /^ <[0..9]> ** 8 $/ means exactly eight digits in the string, and nothing 
else. You have eight characters, but seven of them aren't digits, so the match fails.

Similarly in the second case.


Slowly getting there.



The Perl5 guys had a way of explaining functions that
really worked for me.  You are using the technique, so I
will give it a try and you tell me what I am doing wrong:

my Str $x="abc3defg";
if $x.match( / ^ <[0..9]> ** 8 $ / ) {
   print "True\n"; } else { print "False\n" };
False


$x is the string to test

`.match()` is the test command (method) applied to $x

the beginning and ending `/` are the constraints of the test

`^` means to start testing at the beginning of $x

`$` means to stop testing at the end of $x

`<[0..9]>` are the range of alpha numeric characters
(not numbers) to test for in  $x

`** 8` means to the test each index of $x advancing one at a
time up to  eight times.  Each index of $x is tested for
the existence of <[0..9]>.  The `8` is not the number of
characters in $x.




I am sure I got half of it wrong.

Thank you for the help!
-T




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



Re: .contains question

2023-12-10 Thread ToddAndMargo via perl6-users

On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users  
wrote:

Hi All,

my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; } else { 
print "False\n" };
True

Is there a way to tell .contains that you want to know
if any of a sequence characters is in a string other that
repeating || over and over.  Any [a..z] or [0..9] option?

Many thanks,
-T




On 12/10/23 15:24, Elizabeth Mattijsen wrote:
> my @letters = ;
> if $x.contains(any @letters) {


Hi Elizabeth,

Very interesting.  Problem: I was looking for one answer, not many

> my $x="abc45def";my @y=; print 
$x.contains(any @y) ~ "\n";

True
True
True
True
True
True
False
False
False
False
False
False
False
True
True


Many thanks,
-T

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



Re: Test not working so well

2023-12-10 Thread ToddAndMargo via perl6-users

On 12/10/23 14:16, Kevin Pye wrote:



On Mon, 11 Dec 2023, at 07:31, ToddAndMargo via perl6-users wrote:


[0] > my Str $x="abc3defg"; if $x.match( / ^ <[0..9]> ** 8 $ / ) { print
"True\n"; } else { print "False\n" };
False

"3" is in the string.  Why False?


Because you asked for a match with a string consisting entirely of exactly 8 
digits.


my Str $x="abc3defg"; if $x.match( / ^ <[a..h]> ** 8 $ / ) { print
"True\n"; } else { print "False\n" };
False

a and b and c and d and e and f and g are also in the string.
Why the false?


Because the string doesn't exist of exactly eight letters in the range a..h. 
I.e. there's a 3 in there which isn't a letter in the range a..h.



I am not following.  :'(


.contains question

2023-12-10 Thread ToddAndMargo via perl6-users

Hi All,

my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print 
"True\n"; } else { print "False\n" };

True

Is there a way to tell .contains that you want to know
if any of a sequence characters is in a string other that
repeating || over and over.  Any [a..z] or [0..9] option?

Many thanks,
-T


Re: Test not working so well

2023-12-10 Thread ToddAndMargo via perl6-users

On 12/10/23 12:25, ToddAndMargo via perl6-users wrote:

On 12/9/23 22:49, William Michels via perl6-users wrote:

f $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / ) { do something...};



What is the difference between

     <+[0..9]
and
    <[0..9]


And
     / ^ <+[0..9] + [a..z]> ** 7 $ /

does this mean that both [0..9] AND [a..z] have to
be present.  In other words is the an AND or an OR?


I am confused. What am I missing?

[0] > my Str $x="abc3defg"; if $x.match( / ^ <[0..9] + [h..z]> ** 8 $ / 
) { print "True\n"; } else { print "False\n" };

False

This would mean that both [0..9] and [h..z] would have to match.


[0] > my Str $x="abc3defg"; if $x.match( / ^ <[0..9] + [a..z]> ** 8 $ / 
) { print "True\n"; } else { print "False\n" };

True

This would mean that both [0..9] and [a..z] would have to match.



[0] > my Str $x="abc3defg"; if $x.match( / ^ <[0..9]> ** 8 $ / ) { print 
"True\n"; } else { print "False\n" };

False

"3" is in the string.  Why False?


my Str $x="abc3defg"; if $x.match( / ^ <[a..h]> ** 8 $ / ) { print 
"True\n"; } else { print "False\n" };

False

a and b and c and d and e and f and g are also in the string.
Why the false?




Re: Test not working so well

2023-12-10 Thread ToddAndMargo via perl6-users

On 12/9/23 22:49, William Michels via perl6-users wrote:

f $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / ) { do something...};



What is the difference between

<+[0..9]
and
   <[0..9]


And
/ ^ <+[0..9] + [a..z]> ** 7 $ /

does this mean that both [0..9] AND [a..z] have to
be present.  In other words is the an AND or an OR?





Re: Test not working so well

2023-12-09 Thread ToddAndMargo via perl6-users

On 12/9/23 22:49, William Michels via perl6-users wrote:



On Dec 9, 2023, at 22:12, ToddAndMargo via perl6-users 
 wrote:


On 12/9/23 21:32, ToddAndMargo via perl6-users wrote:

On 12/9/23 19:42, William Michels via perl6-users wrote:



On 12/9/23 17:44, Tom Browder wrote:
> Try: say so $=
>

Would you give me a quick example?


Hi Todd!



HTH, Bill.

Awesome!  Thank you!
:-) :-) :-)



Hi Bill,

I was going to make a keeper out of your examples which explanations.
Not to ask too stupid a question, but what should I call teh keeper?

Many thanks,
-T



Hi Todd,

I should have annotated my examples. I'd just call these "match 
explorations". You'd probably want to write something like:


if $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / ) { do something...};

#Below: use  character class, which also includes underscores. 
Smartmatching with match return:

[0] > my $x="abc2def"; say  $x ~~ / ^  ** 7 $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」


#Below: not a great example (waiting for a fellow Rakoon to chime in and 
explain):

[0] > my $x="abc2def"; .so.put if  $x ~~ / ^  ** 7 $ /;
False


#Below: use `so`. Automatic return in the REPL. But are parentheses 
required?

[0] > my $x="abc2def";   $x ~~ / ^  ** 7 $ /.so;
True


#Below: automatic return in the REPL. Parentheses work:

[1] > my $x="abc2def";   ($x ~~ / ^  ** 7 $ /).so;
True


#Below: use `Bool` instead of `so`:

[2] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /);
True


#Below: use `Bool` to check an 8-character match (should return `False`):

[3] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /);
False


#Below: use `Bool`, back to a  7-character match, add `say`:

[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /).say;
True


#Below: use `Bool`, a  8-character (non)-match, with `say`:

[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /).say;
False


#Below: make a custom `<[0..9] + [a..z]>` character class and test for 7 
(or 8) character match:

[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 8 $ /).say;
False


#Below, add a leading `+` to the custom character class, just to be careful:
[4] > my $x="abc2def";   Bool($x ~~ / ^ <+[0..9] + [a..z]> ** 8 $ 
/).say;

False


##Below, remove `Bool` and rearrange `so` to give final code:
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 
8 $ /;

False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 
7 $ /;

True


HTH, Bill.


Awesome!


Re: Test not working so well

2023-12-09 Thread ToddAndMargo via perl6-users

On 12/9/23 21:32, ToddAndMargo via perl6-users wrote:

On 12/9/23 19:42, William Michels via perl6-users wrote:



On 12/9/23 17:44, Tom Browder wrote:
> Try: say so $=
>

Would you give me a quick example?


Hi Todd!

In the Raku REPL (MoarVM 2023.05):

[0] > my $x="abc2def"; say  $x ~~ / ^  ** 7 $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」
[0] > my $x="abc2def"; .so.put if  $x ~~ / ^  ** 7 $ /;
False
[0] > my $x="abc2def";   $x ~~ / ^  ** 7 $ /.so;
True
[1] > my $x="abc2def";   ($x ~~ / ^  ** 7 $ /).so;
True
[2] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /);
True
[3] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /);
False
[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /).say;
False
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 8 $ /).say;
False
[4] > my $x="abc2def";   Bool($x ~~ / ^ <+[0..9] + [a..z]> ** 8 $ /).say;
False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 8 
$ /;

False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 7 
$ /;

True
[4] >


HTH, Bill.


Awesome!  Thank you!
:-) :-) :-)





Hi Bill,

 I was going to make a keeper out of your examples which explanations.
Not to ask too stupid a question, but what should I call teh keeper?

Many thanks,
-T

--
~~~
Having been erased,
The document you're seeking
Must now be retyped.
~~~


Re: Test not working so well

2023-12-09 Thread ToddAndMargo via perl6-users

On 12/9/23 19:42, William Michels via perl6-users wrote:



On 12/9/23 17:44, Tom Browder wrote:
> Try: say so $=
>

Would you give me a quick example?


Hi Todd!

In the Raku REPL (MoarVM 2023.05):

[0] > my $x="abc2def"; say  $x ~~ / ^  ** 7 $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」
[0] > my $x="abc2def"; .so.put if  $x ~~ / ^  ** 7 $ /;
False
[0] > my $x="abc2def";   $x ~~ / ^  ** 7 $ /.so;
True
[1] > my $x="abc2def";   ($x ~~ / ^  ** 7 $ /).so;
True
[2] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /);
True
[3] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /);
False
[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^  ** 8 $ /).say;
False
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 8 $ /).say;
False
[4] > my $x="abc2def";   Bool($x ~~ / ^ <+[0..9] + [a..z]> ** 8 $ /).say;
False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 8 $ /;
False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 7 $ /;
True
[4] >


HTH, Bill.


Awesome!  Thank you!
:-) :-) :-)


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



Re: Test not working so well

2023-12-09 Thread ToddAndMargo via perl6-users



On Sat, Dec 9, 2023 at 18:22 ToddAndMargo via perl6-users 
mailto:perl6-us...@perl.org>> wrote:


Hi All,

What am I doing wrong here?


my $x="abc2def"; say  $x=/ ^ <[0..9]> ** 7 $ /;
/ ^ <[0..9]> ** 7 $ /

[0] > my $x="abc2def"; say  $x=/ ^ <[l..z]> ** 7 $ /;
/ ^ <[l..z]> ** 7 $ /

[0] >       my $x="abc2def"; say  $x~~/ ^ <[0..9]> ** 7 $ /;
Nil

[0] > my $x="abc2def"; say  $x~~/ ^ <[l..z]> ** 7 $ /;
Nil


I am looking for a True or a False.

Many thanks,
-T


On 12/9/23 17:44, Tom Browder wrote:
> Try: say so $=
>

Would you give me a quick example?


Re: Your idea on how to detect random directory names

2023-12-09 Thread ToddAndMargo via perl6-users

What I have so far:


#!/usr/bin/env perl6

#`{
Clean up the useless to a back up directories in Brave Browser

$ ls ~/.config/BraveSoftware/Brave-Browser
 adcocjohghhfpidemphmcmlmhnfgikei   GrShaderCache
...
}

use lib '/home/linuxutil/p6lib';
use RunNoShellLib :RunNoShell;
use PrintColors :PrintRed, :PrintGreen, :PrintBlue, :PrintErr, 
:PrintRedErr, :PrintGreenErr, :PrintBlueErr;



( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
my Str $BaveDir = %*ENV ~ "/.config/BraveSoftware/Brave-Browser";
my Str $DirsToWhack = "";

for dir $BaveDir -> $Line  {
   # print $Line ~ "\n";
   if  $Line.chars != 79 || $Line.contains( "_" || "-" || " " )  {
  # print "Skip; chars = <" ~ $Line.chars ~ ">  Line = <$Line>\n";
  next;
   }

   # print $Line ~ "\n";
   ( my $DirName  = $Line ) ~~ s/ .* $( Q[/] ) //;
   if  $DirName.lc eq $DirName {
$DirsToWhack ~= $Line ~ "\n";
# print $DirName ~ "\n";
   }
}
# print "Whack directories\n$DirsToWhack\n";

if $DirsToWhack.chars > 0  {
   for $DirsToWhack.lines -> $Line  {
  # PrintBlue "removing <$Line>\n";
  PrintBlue "rm -rf $Line\n";
  RunNoShell "rm -rf $Line";
   }

} else {
   PrintGreen "No directories found to clean out (Whack)\n";
}

# With that, I shall "Whack" no more



Test not working so well

2023-12-09 Thread ToddAndMargo via perl6-users

Hi All,

What am I doing wrong here?


my $x="abc2def"; say  $x=/ ^ <[0..9]> ** 7 $ /;
/ ^ <[0..9]> ** 7 $ /

[0] > my $x="abc2def"; say  $x=/ ^ <[l..z]> ** 7 $ /;
/ ^ <[l..z]> ** 7 $ /

[0] >   my $x="abc2def"; say  $x~~/ ^ <[0..9]> ** 7 $ /;
Nil

[0] > my $x="abc2def"; say  $x~~/ ^ <[l..z]> ** 7 $ /;
Nil


I am looking for a True or a False.

Many thanks,
-T


Re: Your idea on how to detect random directory names

2023-12-09 Thread ToddAndMargo via perl6-users

On 12/8/23 23:41, Paul Procacci wrote:



On Sat, Dec 9, 2023 at 2:06 AM Bruce Gray <mailto:robertbrucegr...@gmail.com>> wrote:




 > On Dec 9, 2023, at 00:37, ToddAndMargo via perl6-users
mailto:perl6-us...@perl.org>> wrote:
 >
 > Hi All,
 >
 > I am writing a clean up routine to relive my spot back ups
 > of junk in Blink browser directories that are meaningless to
 > a backup and that take up a lot of space.
 >
 > These directories are long and have random characters
 > for files names, such as "adcocjohghhfpidemphmcmlmhnfgikei"
 >
 > How who you go about figuring out who was random and
 > who was not.  I am thinking first the length and then
 > the absence of capitol letters and spaces and underscores.
 >
 > Your take?


--snip--

# Brave Browser temp directories: exactly 32 contiguous lowercase
alpha characters.
my $brave_junk_directories_re = / ^ <[a..z]> ** 32 $ /;
my %to_skip = @filenames.grep($brave_junk_directories_re).Set;


I know this really wasn't mentioned clearly, but as a precaution you 
might also want to consider filtering on whether the inode is 
referencing a file or not:


my @to_skip = dir(".", test => { .IO.d && / ^ <[a..z]> ** 32 $ / } ) ;

If that possibility doesn't exist, then I personally would use:

my @to_skip = dir(".", test => { / ^ <[a..z]> ** 32 $ / } ) ;

As always, there's more than one way to skin a cat.

~Paul


I was thinking of something silly, such as first checking that
the length was 32 bits and then comparing the name against the
name in lower case:

$ raku
...
[0] > my $x="abcde"; my $y="aBcde"

[1] > say $x eq $x.lc
True

[1] > say $y eq $y.lc
False




Re: Your idea on how to detect random directory names

2023-12-09 Thread ToddAndMargo via perl6-users

On 12/8/23 23:41, Paul Procacci wrote:



On Sat, Dec 9, 2023 at 2:06 AM Bruce Gray <mailto:robertbrucegr...@gmail.com>> wrote:




 > On Dec 9, 2023, at 00:37, ToddAndMargo via perl6-users
mailto:perl6-us...@perl.org>> wrote:
 >
 > Hi All,
 >
 > I am writing a clean up routine to relive my spot back ups
 > of junk in Blink browser directories that are meaningless to
 > a backup and that take up a lot of space.
 >
 > These directories are long and have random characters
 > for files names, such as "adcocjohghhfpidemphmcmlmhnfgikei"
 >
 > How who you go about figuring out who was random and
 > who was not.  I am thinking first the length and then
 > the absence of capitol letters and spaces and underscores.
 >
 > Your take?


--snip--

# Brave Browser temp directories: exactly 32 contiguous lowercase
alpha characters.
my $brave_junk_directories_re = / ^ <[a..z]> ** 32 $ /;
my %to_skip = @filenames.grep($brave_junk_directories_re).Set;


I know this really wasn't mentioned clearly, but as a precaution you 
might also want to consider filtering on whether the inode is 
referencing a file or not:


my @to_skip = dir(".", test => { .IO.d && / ^ <[a..z]> ** 32 $ / } ) ;

If that possibility doesn't exist, then I personally would use:

my @to_skip = dir(".", test => { / ^ <[a..z]> ** 32 $ / } ) ;

As always, there's more than one way to skin a cat.

~Paul


Hi Bruce and Paul,

   Thank you!

-T



Your idea on how to detect random directory names

2023-12-08 Thread ToddAndMargo via perl6-users

Hi All,

I am writing a clean up routine to relive my spot back ups
of junk in Blink browser directories that are meaningless to
a backup and that take up a lot of space.

These directories are long and have random characters
for files names, such as "adcocjohghhfpidemphmcmlmhnfgikei"

How who you go about figuring out who was random and
who was not.  I am thinking first the length and then
the absence of capitol letters and spaces and underscores.

Your take?

Many thanks,
-T


$ ls ~/.config/BraveSoftware/Brave-Browser
 adcocjohghhfpidemphmcmlmhnfgikei   GrShaderCache
 afalakplffnnnlkncjhbmahjfjhmlkal   hyphen-data
 aoojcmojmmcbpfgoecoadbdpnagfchel   iblokdlgekdjophgeonmanpnjihcjkjj
 apfggiafobakjahnkchiecbomjgigkkn   InterventionPolicyDatabase
 AutofillRegex  iodkpdagapdfkphljnddpjlldadblomo
 AutofillStates'Last Version'
 bfpgedeaaibpoidldhjcknekahbikncb  'Local State'
 biahpgbdmdkfgndcmfiipgcebobojjkp   MEIPreload
 BraveWalletmfddibmblmbccpadfndgakiopmmhebop
 BrowserMetrics-spare.pma   NativeMessagingHosts
 cdbbhgbmjhfnhnmgeddbliobbofkgdhe   OnDeviceHeadSuggestModel
 CertificateRevocation  oofiananboodjbbmdelgdommihjbkfag
 CertificateTransparencyOptimizationHints
 cffkpbalmllkdoenhmdmpbkajipdjfam   OriginTrials
 chrome_shutdown_ms.txt persisted_first_party_sets.json
 ClientSidePhishing PKIMetadata
 component_crx_cache   'Safe Browsing'
 CrashpadMetrics-active.pma'Safe Browsing Cookies'
'Crash Reports''Safe Browsing Cookies-journal'
'Crowd Deny'SafetyTips
 Defaultsegmentation_platform
 Dictionaries   ShaderCache
 ECSerivceProvidersConfig   SSLErrorAssistant
 extensions_crx_cache  'Subresource Filter'
 FileTypePolicies   TLSDeprecationConfig
'First Run' tor
 Floc   TpcdMetadata
 gccbbckogglekeggclmmekihdgdpdgoe   Variations
 gkboaolpopklhgplhaaiboijnklogmbc  'Webstore Downloads'
 GraphiteDawnCache  WidevineCdm
 Greaselion ZxcvbnData
}

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


Re: Raku IO IceDrive bug

2023-11-05 Thread ToddAndMargo via perl6-users



On Oct 22, 2023, at 06:02, ToddAndMargo via perl6-users 
 wrote:


spurt "$TestFile", "Old File Found\n";
spurt "$TestFile", "New File Opened\n";


On 11/5/23 12:08, William Michels via perl6-users wrote:
> Won't adding a `\n` newline to the `spurt()` call eventually cause
> problems?
>
> What happens if you omit the `\n` below?
>
> Best, Bill.
>
>

Hi Bill,

\n just adds a line feed to the file.  Without
it, when I cat the file in my shell, the prompt
for the next command comes up at the end of the
file, rather than on the next line.

-T



Re: is there an AI on the beginner chat line?

2023-10-27 Thread ToddAndMargo via perl6-users




On 10/27/23 04:35, Andinus via perl6-users wrote:

ToddAndMargo via perl6-users @ 2023-10-27 03:19 -07:


On 10/27/23 00:10, Andinus via perl6-users wrote:

ToddAndMargo via perl6-users @ 2023-10-26 21:19 -07:


[...]
They have someone called "discord-raku-bot".  Some of the responses
sound a bit off.  By chance, is discord-raku-bot an AI robot?

That's the discord bridge, connects discord & irc channels.

Is there something actually manning that or is it computer generated?
Some of the responses are really bizarre and can be characterized a
nonsequiturs. Nothing offensive, just out of place as if he was
addressing someone else that you can not see.

Oh, they're actually addressing someone else.

Those messages include the discord username before the message like so:

discord-raku-bot:  ...
discord-raku-bot:  ...

"MyName" & "OtherName" are different users.


Now that make more sense.  Thank you for the explanation.

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



Re: is there an AI on the beginner chat line?

2023-10-27 Thread ToddAndMargo via perl6-users




On 10/27/23 00:10, Andinus via perl6-users wrote:


ToddAndMargo via perl6-users @ 2023-10-26 21:19 -07:


Hi All,

Over onthe beginner's chat linbe:

https://kiwiirc.com/nextclient/irc.libera.chat/#raku-beginner

They have someone called "discord-raku-bot".  Some of the responses
sound a bit off.  By chance, is discord-raku-bot an AI robot?


That's the discord bridge, connects discord & irc channels.





Is there something actually manning that or is
it computer generated?  Some of the responses are
really bizarre and can be characterized a nonsequiturs.
Nothing offensive, just out of place as if he was
addressing someone else that you can not see.


is there an AI on the beginner chat line?

2023-10-26 Thread ToddAndMargo via perl6-users

Hi All,

Over onthe beginner's chat linbe:

https://kiwiirc.com/nextclient/irc.libera.chat/#raku-beginner

They have someone called "discord-raku-bot".  Some
of the responses sound a bit off.  By chance, is
discord-raku-bot an AI robot?

-T

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



Re: Raku IO IceDrive bug

2023-10-22 Thread ToddAndMargo via perl6-users




On 10/21/23 20:50, Ralph Mellor wrote:

Hi again. :)

Let me try again. I'll try cover things more clearly.



#1 There was/is a bug in your code, or at least code that you
say isn't working on your system. (It works on glot.io. See #3)

```
$WanIpFileName.IO.open(:w);
spurt "$WanIpFileName", "New File Opened";
```

These two lines clash badly. They are a bug waiting to
happen. The glot.io system resolves the clash in your
favor, so the clash isn't apparent. You are saying that
on your Windows system, the code fails.

The simplest thing to do is just fix the bug, rather than
worry about understanding it. The simplest way to fix
the bug is to simply drop the first line. It's redundant at
best, and causes the bug at worst, so just get rid of it.

If you don't want to understand the bug, but do want to
know about the other issues, skip ahead to #2 or #3.



In case you *do* want to understand the bug, let's
start with another way to fix the bug. You could write:
```
my $handle = $WanIpFileName.IO.open(:w);
$handle.spurt: "$WanIpFileName", "New File Opened";
```
That works, and should work on Windows.

This time the code *saves the file handle* corresponding
to the first line, and then uses that handle as the invocant
of a `.spurt` *method*, thus connecting the handle opened
in the first line to the `spurt` done in the second line.

Maybe *that* has explained all you need to know. If so,
feel free to skip ahead to #2 or #3.

Repeating the two lines that clashed:
```
$WanIpFileName.IO.open(:w);
spurt "$WanIpFileName", "New File Opened";
```

The first line opens the file in write mode -- and then
leaves it like that and throws away the file handle.

That's an issue. If you understand why it's an issue,
then great. If you don't, then that's OK too, and I'll
move on, because it isn't too important.

The second line has no idea the first line opened the
very same file it's just about to open, so it tries to open
it *again*, write to the file handle, and then close it.

Finally, at program exit, the file system tries to clean
up an exiting process, eg closing any file handles left
open and resolving clashes like your code generates.

On some systems the code will succeed. On your system
you say it doesn't. See #3 for demo and further discussion.



#2 There was/is a doc failure. I now see another one or two.

The doc failed to say that `spurt` opens the file. It should.

(Then you would presumably have understood you did not
need the `open` line.)

The doc failed to say `open` returns a file handle. It should.

(Then you would presumably have understood that if you
used an `open` line, you needed to keep the file handle
and use a `.spurt` *method* on that file handle.)

The example doc you looked at includes a line that does
the equivalent of `touch`. You thought you could use it
but chop off the `.close`.

(But you didn't realize you needed to keep the file handle,
as just explained.)



#3 There is a Windows difference. Your code runs fine on glot.io.

Please click this link, and then the Run button:

https://glot.io/snippets/gpv7tdaca0

That contains your code. And it's working. The difference is it's not Windows.

NB. Each time you click Run, glot.io automatically cleans the
file system. Every time. That's why it always says 'file does
not exist' at the start. Every time.

NB. I added the lines declaring the missing variable and sub,
and checking the file does not exist at the start, and some
commented out stuff and so on. Feel free to edit the code to
whatever you want if you want to. If you want to start over,
click refresh on your browser and click 'Reload'.


love, raiph




Hi Raiph,

Thank you for all the time you spent on this!  It
is extremely appreciated.



I wrote a little test code:

WinCreateFileTest.pl6
~~~
#!/usr/bin/env raku

sub DirectoryExists( Str $DirPath --> Bool ) { return 
"$DirPath".IO.d.Bool; }  # $Full DirPath format is `H:\MyDocsBackup`
sub DriveExists( Str $DriveLetter --> Bool ) { return 
"$DriveLetter".IO.e.Bool; }  # $Drive Letter format is `A:\`
sub Exists(  Str $Path--> Bool ) { return 
"$Path".IO.e.Bool; } # file, dirctory, drive
sub FileExists(  Str $FilePath--> Bool ) { return 
"$FilePath".IO.f.Bool; } # $File Path format is `H:\IAmBackup`



my Str $TestFile = "WinEraseme.txt";

if FileExists( $TestFile )  {
   print "Previous $TestFile found.\n";
   spurt "$TestFile", "Old File Found\n";

} else {
   $TestFile.IO.open(:w).close;
   spurt "$TestFile", "New File Opened\n";
}

print Q[Now run `type ] ~ $TestFile ~ Q[`] ~ " to check your results\n"
~~


>del WinEraseme.txt

>raku WinCreateFileTest.pl6
Now run `type WinEraseme.txt` to check your results

>type WinEraseme.txt
New File Opened


>raku WinCreateFileTest.pl6
Previous WinEraseme.txt found.
Now run `type WinEraseme.txt` to check your results

>type WinEraseme.txt
Old File Found

~~~

So clearly, Windows 

Re: Raku IO IceDrive bug

2023-10-16 Thread ToddAndMargo via perl6-users




On 10/16/23 06:54, Ralph Mellor wrote:

if not FileExists( $WanIpFileName )  {
 $WanIpFileName.IO.open(:w);
 spurt "$WanIpFileName", "New File Opened";
}


Afaik, depending on how you choose to look at things,
there's a doc error (doc for `spurt` doesn't mention that
it opens the file it's spurting to), and/or behavior due to
your Windows file system / account settings that leads
to the issue you see, and/or a bug in your code.

Let me explain. Here's what the code does:

1. Opens the file with `$WanIpFileName.IO.open(:w);`
if it doesn't already exist.

2. Opens the file with `spurt` and writes to it.

And that causes the behavior you see.

Presumably, on your system/setup, doing those two things
fails because the second open fails due to the first one.

So it succeeds the second time around because the file
already exists (though blank) and the `spurt` goes ahead.

I'd argue that the bug is ultimately in your code, perhaps
due to you not realizing that `spurt` opens the file it spurts
to, because the doc doesn't say so.

Whichever way one looks at it, there's no bug in Raku(do).

--
love, raiph



Hi Raiph,

Interesting.  Be nice if it was me.  I can fix me.
I can't fix bugs in languages.

Looking at
https://docs.raku.org/type/IO::Path

I only find one instance of IO.open and it is an
example for "unlink"

'foo.txt'.IO.open(:w).close;

I was using it to create a file.  I can not find
any discussion of that.

And I could find no discussion of file locks either.

spurt "$WanIpFileName", "New File Opened";

was only added to see it I could write to the newly
created file.  Apparently, not.  And no error message
complaining about being denied access (file lock?).

Maybe I am opening a handle that is blocking
spurt from writing to the file.  It should not
matter, but apparently is does.

And if the above is the case, it is a bug in Raku.

Maybe I should have done
$WanIpFileName.IO.open(:w).close;


What I need is what function Raku is using to support fileapi.h:
CreateFileA function (fileapi.h)

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea

And I see that fileapi.h is also opening a handle
which probably should also be closed.

I really do not feel like writing the api call myself.

Thank you for the help,
-T

p.s.  I adore Linux's "touch" command.





Raku IO IceDrive bug

2023-10-09 Thread ToddAndMargo via perl6-users

Hi All,

Windows 10 22H2
Windows 11 22H2

RakudoMoar-2023.09.01-win-x86_64-msvc.msi
https://github.com/AntonOks/rakudo-star-win/releases
Note: zef requires git

An IO bug with Windows Ice Drive to report. (I
no longer report them the the bug reporter as I
have zero luck.)

Ice Drive is a cloud storage service that allows
you to use a local drive letter in Windows.

A free account is available from
https://icedrive.net/apps/desktop-laptop

The following will only open a blank file,
regardless of what you then write to it.
The second time you run your program and
the file already exists, it will work properly:


if not FileExists( $WanIpFileName )  {
   $WanIpFileName.IO.open(:w);
   spurt "$WanIpFileName", "New File Opened";
}


Then if you write to the file, nothing goes
into the file.  But when you run the program
a second time, all is well.  Note that the
blank file already exists the second time through.


The work around:

I wrote the following sub to deal with Raku
not being able to handle quotes properly
when trying to run a windows helper program.


my $PathIAm  = $?FILE;
   $PathIAm ~~ s:global| '/' |\\|;

sub RunCmd( Str $CommandStr, Bool $EchoOff = False )  {
   my Str $BatFile = $PathIAm ~ ".bat";
   my Str $RtnStr;
   my Str $CmdStr = "";

   if $EchoOff  { $CmdStr = Q[@echo off] ~ "\n"; }
   $CmdStr = $CmdStr ~ $CommandStr ~ "\n";
   # print "$CmdStr\n";

   spurt( $BatFile, $CmdStr );
   $RtnStr = qqx { $BatFile };
   # print "$RtnStr\n";
}

RunCmd Q[echo New File Opened > ] ~ $WanIpFileName;


And happy camping returns.  I can write anything
I want to the file after that and it takes.

-T





Raku. how 102 uses!

2023-10-07 Thread ToddAndMargo via perl6-users

Hi All,

This is just silly, but I thought I'd share it anyway.

I was trying to enter something into my
home purchase orders database that I had copied and pasted
from a web page and I also wanted it into a newsgroup post
I was making.  Problem, it was all upper case.  So I
put it into Libre Office and switched it to lower case.
But when I went to copy and paste it, it came out in
upper case again.  Frustrating.  Then I remembered I
know Raku.


p6 'say "VINTAGE ROBERTSHAW ROOM THERMOSTAT MODEL 260D-1, BRAND NEW N 
BOX".lc;'


vintage robertshaw room thermostat model 260d-1, brand new n box


Now I could copy and paste!

Raku.  Now 100 and two uses!

Chuckle.

-T

ps   alias p6='perl6 -e'
Got it from Larry Wall.


Slow???

2023-08-17 Thread ToddAndMargo via perl6-users

Hi All

Fedora 38

$ raku -v
Welcome to Rakudo™ v2023.06.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2023.06.


Has the compiler gotten really, really, really
slow lately?

What normally takes 8 seconds is now dragging on
for minutes,

$ raku -c GetUpdates.pl6

Perplexed,
-T


Found the source of the drag, but it is still slow.

 #`(
 Aug 08, 2023
 
 href="https://www.adobe.com/devnet-docs/acrobatetk/tools/ReleaseNotesDC/continuous/dccontinuousaug2023.html\
  #dccontinuousaugtwentytwentythree" 
disablelinktracking="false">\

  DC Aug 2023 (23.003.20269)
 
 Continuous
 
 Latest Release: This update provides new features, 
security mitigations, feature enhancements, and bug fixes.

  }

#`( should have been #`{



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


Re: A question on AND

2023-07-01 Thread ToddAndMargo via perl6-users

> On 30/06/2023 06:06, ToddAndMargo via perl6-users wrote:
>> if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}

On 6/30/23 02:40, Richard Hainsworth wrote:

I tried this and it worked without any problem.


And today is is working for me as well without
a problem. I must have had something else wrong
taht I did not recognize.  So false alarm.



Here's the whole program:

use v6.d;
say @*ARGS.raku;
if @*ARGS.elems > 0 && "@*ARGS[0]".lc eq "debug" {
 say 'got' }
and at the terminal:

$ raku todd-test.raku debug --debug=50
["debug", "--debug=50"]
got


FWIW
why are you quoting ARGS? The .lc coerces to string anyway.


It is a habit from programming in bash.  I did not even
realize I had done it.  And I dp prefer Raku's
way of doing it.


why are you using && and not 'and'


See Yary's response.


why are you not using a sub MAIN with an optional --debug
eg. sub MAIN( @args, Bool :$debug=False) {
#stuff
if $debug { ... }


Because it is less complicated for what I am doing.

Thank you for the help!

-T



A question on AND

2023-06-29 Thread ToddAndMargo via perl6-users

Hi All,

This gets the finger wagged at me for a "Nil"
when @*ARGS.elems equals zero:

if @*ARGS.elems > 0  &&  "@*ARGS[0]".lc eq "debug"  {...}


I have to do this instead:

if @*ARGS.elems > 0  {
   if "@*ARGS[0]".lc eq "debug"  {...}
}


Do I misunderstand something?  In an AND, is
not the test suppose to stop at the first fail?

I have not checked OR, but is that not suppose
to jump out at the first pass?  Or does it
check everything too?

Many thanks,
-T







Tip: my keeper example of qqx and match

2023-06-23 Thread ToddAndMargo via perl6-users

Hi All,

I wrote myself a nice example of how to use `qqx`
and `m:` (match).   It is pretty simple, so it
is probably "way under" the heads of most of you.
But it is a nice example for beginners:


Notes:
   resplendence.com is the home of "Who Crashed":
   a great utility for Windows users.

   the example requires `curl` to be installed.

   tests of the example were run under Fedora
   Linux V 37.  Windows was not tested.



#!/bin/raku

my Str $WebSite = "https://www.resplendence.com/main;;
my Str $Match   = "";

$WebSite = qqx { curl -L "$WebSite" -o - };
print "\n";

#`{ $WebSite line 913 to 916 (as of 2023-06-23)


WhoCrashed has been updated to v 7.06.
To see what's changed bold">click here.


}

if not  $WebSite~~m:i/ .*? ( "WhoCrashed has been updated to v ")  (.*?) 
(".") (.*?) "." / {

   print "The match failed.  Cowardly Exiting.  Bummer Dude!\n";
   exit;
}

print "\$0 = <" ~ $0 ~ ">\n";
print "\$1 = <" ~ $1 ~ ">\n";
print "\$2 = <" ~ $2 ~ ">\n";
print "\$3 = <" ~ $3 ~ ">\n\n";

$Match = $1 ~ $2 ~ $3;
print "Version (Match) = <" ~ $Match ~ ">\n";
print "Expected output = <7.06>  until the next update\n\n";
/


Result:

$ RegexTest2.pl6
  % Total% Received % Xferd  Average Speed   TimeTime Time 
Current
 Dload  Upload   Total   SpentLeft 
Speed
100 74882  100 748820 0   225k  0 --:--:-- --:--:-- --:--:-- 
 225k


$0 = 
$1 = <7>
$2 = <.>
$3 = <06>

Version (Match) = <7.06>
Expected output = <7.06>  until the next update


-T




Re: Is this a regex bug?

2023-06-20 Thread ToddAndMargo via perl6-users

On 6/20/23 13:32, Bruce Gray wrote:




On Jun 19, 2023, at 18:50, ToddAndMargo via perl6-users  
wrote:

Hi All,

Fedora 37
RakudoPkgFedora37-2023.05.01.x86_64.rpm
https://github.com/nxadm/rakudo-pkg/releases

The `/$0$1 $2/` is not coming out correct.
Is this a bug or did I do something wrong?


--snip--
# Is this a bug or did I do something wrong?

You did something wrong.

You said "FOO is not coming out correct", without telling us what "correct" you 
were expecting, or trying to obtain.
So, I am guessing what particular aspect of the output you are 
displeased/suprised by.

1. If the issue is that $x contains more than just "$0$1 $2",
the reason is that you are missing `.* $` at the end of your regex.

I was initially mystified by the unexpectedly-long result in `$x`;
I detected the source of the problem by changing your substitution
of /$0$1 $2/ to /aaa $0 bbb $1 ccc $2 ddd / for examination.
Just add `.* $` to the end of your pattern, and the s/// will destroy 
everything after the match,
as it did to the part before the match.

2. If the issue is that $1 contains `i686` and $2 contains `x86_64`
(which would be a suprising thing to want, and is better handled outside of a 
regex),
then the reason is that your regex specifies `a href=` *second* in each line,
while the actual data has the `a href=` occuring *first*. So, the pattern is 
matching across lines.

I (still guessing) have coded a quick parsing the way I might have done, and 
solutions to variants of (2.) above.

BTW:
 * I am unclear if the destructive effect of `$x ~~ s///` is needed for 
your intentions.
 If you are just trying to parse, `.match` seems better.
 * You included the input you are trying to match against, which was 
critial in understanding as much as I did.
 Did you alter the input data, though?
 Specifically, does your actual input lack newlines between the "lines" 
of data, the way your `$x` lacks them?
 * If your input data is line-oriented, and you can reliably break it up 
into .lines(), then doing that pre-segmenting
  and running a regex on each individual line is a better way of 
efficiently keeping the regex speedy
 and not accidentally spanning lines.
 * You have HTML in your input data.
 The reflexive advice every time this comes up is "Do not parse HTML with 
regex; use a HTML parser".
 (We all parse HTML with regex anyway, on occasion; regex are just so 
easy to reach for.)
 To encourge you to consider the "correct" approach, I have appended a 
solution in just 6 SLOC.




Hi Bruce,

Thank you for the technical writing feedback and
the Raku tips!

I use to use "for $WebPage.line -> $Line {...}",
but it is a lot easier to use regex.   (I do ADORE
the .lines  method though.)


Let me trying writing the question a little bit better.

The code in question:

$ curl -L http://vpaste.net/pxRm6 -o -

#!/bin/raku

print "\n";
my Str $x = Q[href="wike-2.0.1-1.fc38.noarch.rpm">wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K] ~
Q[href="wine-8.6-1.fc38.i686.rpm">wine-8.6-1.fc38.i686.rpm 19-Apr-2023 
21:48  11K] ~
Q[href="wine-8.6-1.fc38.x86_64.rpm">wine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11K] ~
Q[href="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm 
19-Apr-2023 21:48  223K] ~

"\n\n";

$x~~s:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a href="] ) 
(.*?) ( $(Q[">] ) )  /$0$1 $2/;

print "0 = <$0>\n1 = <$1>\n2 = <$2>\n\n";
print "$x\n\n";



Correct results of:
print "0 = <$0>\n1 = <$1>\n2 = <$2>\n\n";
0 = 
1 = <-8.6-1.fc38.i686.rpm>
2 = 

The above is correct and what I wanted.  And shows that
$0, $1, and $2 contain the correct values I wanted.


Incorrect result of:
$x~~s:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a href="] ) 
(.*?) ( $(Q[">] ) )  /$0$1 $2/;


wine-8.6-1.fc38.i686.rpm 
wine-8.6-1.fc38.x86_64.rpmwine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11Khref="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm 
19-Apr-2023 21:48  223K



Expected result of the above:
   wine-8.6-1.fc38.i686.rpm wine-8.6-1.fc38.x86_64.rpm


If you are wonder what I am up to with all this,
Wine-staging 7 and 8 under Fedora do not print
from Lotus Approach or Lotus Smart Suite.  The bug
has been report to and is currently being worked
on by the Wine folks.  Wine has since asked if I
would test Wine-Staging 8.10.  But if I
spin it myself I trash my rpm database.  So I am
waiting from my request to Fedora to add wine-staging
8.10 to the repos.

Now I could check DNF to see if 8.10 is in the
repo

Is this a regex bug?

2023-06-19 Thread ToddAndMargo via perl6-users

Hi All,

Fedora 37
RakudoPkgFedora37-2023.05.01.x86_64.rpm
https://github.com/nxadm/rakudo-pkg/releases

The `/$0$1 $2/` is not coming out correct.
Is this a bug or did I do something wrong?


Many thanks,
-T


$ curl -L http://vpaste.net/pxRm6 -o -

#!/bin/raku

print "\n";
my Str $x = Q[href="wike-2.0.1-1.fc38.noarch.rpm">wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K] ~
Q[href="wine-8.6-1.fc38.i686.rpm">wine-8.6-1.fc38.i686.rpm 
19-Apr-2023 21:48  11K] ~
Q[href="wine-8.6-1.fc38.x86_64.rpm">wine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11K] ~
Q[href="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm 
 19-Apr-2023 21:48  223K] ~

"\n\n";

$x~~s:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a href="] )  (.*?) 
( $(Q[">] ) )  /$0$1 $2/;

print "0 = <$0>\n1 = <$1>\n2 = <$2>\n\n";
print "$x\n\n";



$ RegexTest.pl6

0 = 
1 = <-8.6-1.fc38.i686.rpm>
2 = 

wine-8.6-1.fc38.i686.rpm 
wine-8.6-1.fc38.x86_64.rpmwine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11Khref="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm 
 19-Apr-2023 21:48  223K


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


Re: Need regex in the middle wildcard help

2023-06-19 Thread ToddAndMargo via perl6-users

On 6/19/23 07:39, Richard Hainsworth wrote:

HI Todd,

Some more clean up:

On 19/06/2023 12:41, ToddAndMargo via perl6-users wrote:



This is my test program:


#!/bin/raku

print "\n";
my Str $x = Q[href="wike-2.0.1-1.fc38.noarch.rpm">wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K] ~
 Q[href="wine-8.6-1.fc38.i686.rpm">wine-8.6-1.fc38.i686.rpm 
19-Apr-2023 21:48  11K] ~
 Q[href="wine-8.6-1.fc38.x86_64.rpm">wine-8.6-1.fc38.x86_64.rpm 
 19-Apr-2023 21:48 11K] ~
 Q[href="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm   19-Apr-2023 21:48  223K];


$x~~m:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a href="] )  
(.*?) ( $(Q[">] ) )  /;


print "0 = <$0>\n1 = <$1>\n2 = <$2>\n\n";

my Str $y = $0 ~ $1 ~ " " ~ $2;
print "$y\n\n";



$ RegexTest.pl6

0 = 
1 = <-8.6-1.fc38.i686.rpm>
2 = 

wine-8.6-1.fc38.i686.rpm wine-8.6-1.fc38.x86_64.rpm



After Joseph's help:
  $SysRev  = $WebPage;
  $SysRev~~m:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a 
href="] )  (.*?)  ( $(Q[">] ) )  /;

  $SysRev = $0 ~ $1 ~ "   " ~ $2;



maybe the following would be a bit more Raku-ish

[in file called todd-test.raku]

$=finish ~~ /:i ['href="' ~ \" $ = ( 'wine-' \d .+? ) .*? ]+ $ /;
say $/.join(' ');

=finish wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K
wine-8.6-1.fc38.i686.rpm 19-Apr-2023 
21:48  11K
wine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11K
wine-alsa-8.6-1.fc38.i686.rpm  
19-Apr-2023 21:48  223K

[end of todd-test.raku]
Test it in a terminal:

$ raku todd-test.raku
wine-8.6-1.fc38.i686.rpm wine-8.6-1.fc38.x86_64.rpm

Some comments.
1) `=finish` is an undocumented part of the POD6 specification (I only 
discovered it recently). It will be documented soon.
Anything after `=finish` is put in string that can be pulled into a Raku 
program with `$=finish` (also undocumented)
`=finish` was introduced instead of Perl's `__DATA__`.
It is useful, because if you have alot of text to be experimented on, just 
attach the text to the bottom of the program after a =finish
2) `~~` does not need a `m` (you only need 'm' if you want to associated a 
regex with the topic, eg. $_)
3) the /  'begin' ~ 'end' 'regex'  / syntax means match the regex between 
'begin' and 'end'.
4) The final output has a 'wine' in it, so why search for it separately? Just 
include it in the search.
5) You seem to be looking for a 'wine-' followed by a digit, so as to eliminate 
the 'wine-alsa-' line, so look for that
6) '$=' places the match into $/ of the whole match. Multiple matches 
create an array.
7) `$/.join` takes an array and joins it with a separator.
8) In the original code, all the $() and Q[] add noise without any 
disambiguation.

But then we want to pull out interesting bits and we are not interested in the 
rest. So `comb` is better.

[start of test-2.raku]

$=finish.comb(/ 'wine-' \d .+?  /).join(' ').say;

=finish wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K
wine-8.6-1.fc38.i686.rpm 19-Apr-2023 
21:48  11K
wine-8.6-1.fc38.x86_64.rpm 
19-Apr-2023 21:48 11K
wine-alsa-8.6-1.fc38.i686.rpm  
19-Apr-2023 21:48  223K

[end of test-2.raku]


Same output.

Notes:
1) comb looks for all matches in a string, so no need for the repeat and end of 
line in the regex
2) We are looking for something 'after' a 「"」 and 'before' a second 「"」, and so we can use 
the  and  zero-width matchers.

Richard, aka finanalyst


Hi Richard,

Perhaps, but way over my head.  I will have to read
over what you wrote several times before it gets
though the proverbial cement.  Thank you!

-T



Re: Need regex in the middle wildcard help

2023-06-19 Thread ToddAndMargo via perl6-users

On 6/19/23 03:03, ToddAndMargo via perl6-users wrote:

On 6/18/23 05:38, ToddAndMargo via perl6-users wrote:

Hi All,

I know how to do this with several regex's and words.
What I'd like to learn is how to remove something
from the middle with regex using a wild card.

And I can't figure it out


#!/bin/raku

print "\n";
my Str $x = Q[wine-7.12-3.fc37.i686.rpm    23-Jul-2022 19:11  
11K 
print "1 [$x]\n\n";

$x~~s/ $( Q[] )  *  $( Q[a href="] ) / /;
print "2 [$x]\n\n";



1 [wine-7.12-3.fc37.i686.rpm    23-Jul-2022 19:11  11K   href="wine-7.12-3.fc37.x86_64.rpm]


2 [wine-7.12-3.fc37.i686.rpm    23-Jul-2022 19:11  11K   < 
wine-7.12-3.fc37.x86_64.rpm]




My goal is to have `2` print the following out

wine-7.12-3.fc37.i686.rpm wine-7.12-3.fc37.x86_64.rpm


Many thanks,
-T



 > On 6/18/23 12:10, Joseph Brenner wrote:

References: 

Try something like this, perhaps:

 $x ~~ s:i/ ^ (.*?) '' .*?  '

'...'   I'm using single quotes on the literal strings

$  match all the way to the end of the string.

Pinning the match with ^ and $ means a s/// will replace the entire 
string.


There are two captures, so they load $0 and $1, and here we're using
them in the replace string:    s/.../$0 $1/


Hi Joseph,

Right under my nose!  Thank you.

This is my test program:


#!/bin/raku

print "\n";
my Str $x = Q[href="wike-2.0.1-1.fc38.noarch.rpm">wike-2.0.1-1.fc38.noarch.rpm 
27-Apr-2023 01:53  143K] ~
     Q[href="wine-8.6-1.fc38.i686.rpm">wine-8.6-1.fc38.i686.rpm 19-Apr-2023 
21:48  11K] ~
     Q[href="wine-8.6-1.fc38.x86_64.rpm">wine-8.6-1.fc38.x86_64.rpm 
     19-Apr-2023 21:48 11K] ~
     Q[href="wine-alsa-8.6-1.fc38.i686.rpm">wine-alsa-8.6-1.fc38.i686.rpm 
  19-Apr-2023 21:48  223K];


$x~~m:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a href="] )  (.*?) ( 
$(Q[">] ) )  /;


print "0 = <$0>\n1 = <$1>\n2 = <$2>\n\n";

my Str $y = $0 ~ $1 ~ " " ~ $2;
print "$y\n\n";



$ RegexTest.pl6

0 = 
1 = <-8.6-1.fc38.i686.rpm>
2 = 

wine-8.6-1.fc38.i686.rpm wine-8.6-1.fc38.x86_64.rpm



From my actual program:

Before Joseph's help:
  $SysRev  = $WebPage;
  $SysRev ~~ s/ .*? $( Q[a href="wine] ) /wine/;
  $SysRev ~~ s/ $( Q[x86_64.rpm] ) .* /x86_64.rpm/;
  $SysRev ~~ s/ $( Q[">wine] ) / /;
  $SysRev  = $SysRev.words[0] ~ " " ~ $SysRev.words[6];
  $SysRev ~~ s/ $( Q[href="] ) //;
  $SysRev ~~ s/ $( Q[] ) //;

After Joseph's help:
  $SysRev  = $WebPage;
  $SysRev~~m:i/  .*? ("wine")  (.*?)  $(Q[">] )  .*?  $( Q[a 
href="] )  (.*?)  ( $(Q[">] ) )  /;

  $SysRev = $0 ~ $1 ~ "   " ~ $2;

Awesome cleanup!

-T


  1   2   3   4   5   6   7   8   9   10   >