From: Joseph Brenner via perl6-users
We've got the Raku Study group going, even as I type. Sorry if the email address change is confusing: doomvox is now tailormoon@pm.me
Zoom meeting link:
https://us02web.zoom.us/j/85308554316?pwd=52Bc9BpWgd7Xsi6tqQT2QhSQ8eWDkM.1
Passcode: 4RakuRoll
From: William Michels via perl6-users
From Raku's `rename` man-page:
"Note: some renames will always fail, such as when the new name is on a different storage device. See also: move."
https://docs.raku.org/routine/rename
HTH, Bill.
PS. If you want Raku code fitting a 'create-backup; unlink-original; copy-backup-to-original-location' strategy, look here:
https://unix.stackexchange.com/questions/749558/remove-exact-line-from-file-if-present-leave-the-rest-of-lines-error-handling/749581#749581
> On Apr 3, 2025, at 19:05, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
>
> > On Thu, Apr 3, 2025 at 2:14â¯AM ToddAndMargo via perl6-users <perl6-
> > users@perl.org <mailto:perl6-users@perl.org>> wrote:
> >
> > And another IO ffunctio that does ot work:
> >
> > RotateArchives: renaming directory
> > \\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6 to
> > \\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4
> >
> > Failed to rename
> > 'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6' to
> > 'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4': Failed to
> > rename file: no such file or directory
> >
> > rename put a freaking C: on teh unc path.
> >
> > Another call to powershell. Poop!
> >
> >
> On 4/3/25 12:08 PM, yary wrote:
>> The first 3 characters of the error is telling you the problem
>> C:\192
>> it's same as in another thread, use Q[\\192 ... instead of '\\192 ... , so that you preserve the backslashes.
>
> That other thread had that path in a variable. Raku messed
> with the variable when I made the IO call. And I
> can not put a variable into a Q[]. AAAAAA HHHH !!!!
>
>> OR
>> double each backslash- `\\\\192.168.240.10\\oldserver ... and then you can keep using variables as you normally do.
>> -y
>
> Hi Yary,
>
> This is a glaring bug.
>
> The call was
> rename $Oldpath $NewPath
>
> $OldPath was `\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6`
> $NewPath was `\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4`
>
> Once I have something added to a variable, it is HANDS OFF. DO
> NOT MESS WITH IT. Before then, it is appreciated. BUT NOT AFTER!
>
> Not only did rename mess with my variables, but it added `C:` to it.
>
> If the powers-that-be ever decide to fix IO under Windows, any workaround I do to get around the current situation will
> be broken. And back to chasing ghosts again.
>
> My solution is to add powershell calls to my NativeWinUtils.rakumod
> and use them instead of raku's IO calls.
>
> An example:
>
> sub DirectoryExists( Str $DirPath --> Bool ) {
> # $Full DirPath format is \\192.168.240.10\oldserver\Backup\MyDocsBackup\backup
> my $SubName = &?ROUTINE.name;
> my Str $RtnStr = RunCmd "powershell Test-Path $DirPath", True;
> $RtnStr = $RtnStr.chomp;
> if $CommandLine.debug { print "$SubName: powershell Test-Path returned <$RtnStr> for <$DirPath>\n\n"; }
> if $RtnStr.lc.contains( "true" ) { return True; } else { return False; }
> }
>
> Oh ya, and the above actually works!
>
> Forgive my being crabby. I have been coding on this project
> for over a week. It was only suppose to take a day. I have
> been CHASING GHOSTS. I am really, really tired. Now I have
> to remove all of the IO calls from my code and replace them
> with calls to powershell. AAAA HHHH !!!!!! At least I
> have finally figured out what was going wrong.
>
> Thank you for the help!
>
> -T
>
>
>
>
>
>
From: Joseph Brenner
And riding fast on the heels of the last one, comes The Raku Study Group:
"There is no idea so frivolous or odd which does not appear
to me to be fittingly produced by the mind of man. Those
of us who deprive our judgment of the right to pass
sentence look gently on strange opinions; we may not lend
them our approbation but we do readily lend them our ears."
Michel de Montaigne, "The Art of Conference" (1588)
Translation: M.A. Screech
April 13, 2025 1pm in California, 8pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/89366078473?pwd=Iu8rQKIeZ3vRlhDZbaalmXAW8EJRkq.1
Passcode: 4RakuRoll
From: ToddAndMargo via perl6-users
Hi All,
I am not having any luck printing the values of a OOP
structure, except for printing them one at a time. I
can get it to messily print with `say`, but I want to
do it with `print` so I can control the line feeds,
comments, etc..
What am I doing wrong?
Many thanks,
-T
[0] > class PartitionClass{
has Str $.DeviceID is rw;
has Str $.VolumeName is rw;
has Str $.ProviderName is rw;
has Str $.UNC_BackupPath is rw;
has Int $.DriveType is rw;
has Str $.DriveTypeStr is rw;
has Int $.FreeSpace is rw;
has Int $.Size is rw;
has Int $.PercentUsed is rw;
has Int $.PercentRemaining is rw;
}
(PartitionClass)
[1] > my $Partition = PartitionClass.new(
DeviceID => "",
VolumeName => "",
ProviderName => "",
UNC_BackupPath => "",
DriveType => 0,
DriveTypeStr => "Unknown",
FreeSpace => 0,
Size => 0,
PercentUsed => 0,
PercentRemaining => 100
);
PartitionClass.new(DeviceID => "", VolumeName => "", ProviderName => "",
UNC_BackupPath => "", DriveType => 0, DriveTypeStr => "Unknown",
FreeSpace => 0, Size => 0, PercentUsed => 0, PercentRemaining => 100)
[2] > for $Partition.kv -> $i, $j { print "i <$i> j <$j>\n" }
i <0> j <PartitionClass<4875316684000>>
[2] > print $Partition ~ "\n";
PartitionClass<4875316684000>
[2] > say $Partition;
PartitionClass.new(DeviceID => "", VolumeName => "", ProviderName => "",
UNC_BackupPath => "", DriveType => 0, DriveTypeStr => "Unknown",
FreeSpace => 0, Size => 0, PercentUsed => 0, PercentRemaining => 100)
From: ToddAndMargo via perl6-users
On 4/5/25 6:58 PM, ToddAndMargo via perl6-users wrote:
> sub Directory
I changed the name to DirectoryExists
The new name is more human friendly
From: ToddAndMargo via perl6-users
On 4/2/25 6:08 PM, Bruce Gray wrote:
>
>
>> On Apr 2, 2025, at 19:47, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
>
> --snip--
>
>> raku -e "say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1'.IO.d.Bool;"
>> False
>
> --snip--
>
> Moving this one-liner into a .raku file (to remove the complication of Windows needing double-quotes for our `-e`), and removing `.IO.d.Bool`, I ran just this line:
> say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1';
> The output is:
> \192.168.240.10\oldserver\Backup\MyDocsBackup\backup1
> So, the initial two backslashes are becoming a single backslash.
> You need a quoting that does not special-case doubled backslashes (like the Q[] I have seen you use), or to enter the path with initial quadruple backslashes.
>
> Does changing your one-liner to this:
> raku -e "say Q[\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1].IO.d.Bool;"
> fix the problem?
> If not, remove the `.Bool` just for a test run. You might still get False (like if the path exists but is not a directory), or you might get a Exception that gives you more detail of what is going wrong (like `Failed to find ...`, with the exact path that it was *actually* looking for).
>
Hi Bruce,
I need the function to operate with the exact path
assigned by Windows. No adding or subtracting.
This was my work around:
sub Directory( Str $DriveDirectory ) returns Bool is export( :Directory ) {
# True if a Directory or Drive Letter
my Str $RtnStr = RunCmd( "powershell.exe test-path -Path " ~ Q["]
~ $DriveDirectory ~ Q["] ~ " -PathType Container", True );
# print "RtnStr = <$RtnStr>\n";
if $RtnStr.lc.starts-with( "true" ) { return True; } else { return
False; }
}
Notice that I did not have to mess the `$DriveDirectory`?
.IO.d.Bool needs to do the same.
Let me know if you want the code for `RunCmd`.
Thank you for the help,
-T
From: Bruce Gray
> On Apr 2, 2025, at 19:47, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
--snip--
> raku -e "say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1'.IO.d.Bool;"
> False
--snip--
Moving this one-liner into a .raku file (to remove the complication of Windows needing double-quotes for our `-e`), and removing `.IO.d.Bool`, I ran just this line:
say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1';
The output is:
\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1
So, the initial two backslashes are becoming a single backslash.
You need a quoting that does not special-case doubled backslashes (like the Q[] I have seen you use), or to enter the path with initial quadruple backslashes.
Does changing your one-liner to this:
raku -e "say Q[\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1].IO.d.Bool;"
fix the problem?
If not, remove the `.Bool` just for a test run. You might still get False (like if the path exists but is not a directory), or you might get a Exception that gives you more detail of what is going wrong (like `Failed to find ...`, with the exact path that it was *actually* looking for).
--
Hope this helps,
Bruce Gray (Util of PerlMonks)
From: ToddAndMargo via perl6-users
> On Thu, Apr 3, 2025 at 2:14â¯AM ToddAndMargo via perl6-users <perl6-
> users@perl.org <mailto:perl6-users@perl.org>> wrote:
>
> And another IO ffunctio that does ot work:
>
> RotateArchives: renaming directory
> \\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6 to
> \\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4
>
> Failed to rename
> 'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6' to
> 'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4': Failed to
> rename file: no such file or directory
>
> rename put a freaking C: on teh unc path.
>
> Another call to powershell. Poop!
>
>
On 4/3/25 12:08 PM, yary wrote:
> The first 3 characters of the error is telling you the problem
>
> C:\192
>
> it's same as in another thread, use Q[\\192 ... instead of '\\192 ... ,
> so that you preserve the backslashes.
That other thread had that path in a variable. Raku messed
with the variable when I made the IO call. And I
can not put a variable into a Q[]. AAAAAA HHHH !!!!
> OR
>
> double each backslash- `\\\\192.168.240.10\\oldserver ... and then you
> can keep using variables as you normally do.
>
> -y
Hi Yary,
This is a glaring bug.
The call was
rename $Oldpath $NewPath
$OldPath was `\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6`
$NewPath was `\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4`
Once I have something added to a variable, it is HANDS OFF. DO
NOT MESS WITH IT. Before then, it is appreciated. BUT NOT AFTER!
Not only did rename mess with my variables, but it added `C:` to it.
If the powers-that-be ever decide to fix IO under Windows, any
workaround I do to get around the current situation will
be broken. And back to chasing ghosts again.
My solution is to add powershell calls to my NativeWinUtils.rakumod
and use them instead of raku's IO calls.
An example:
sub DirectoryExists( Str $DirPath --> Bool ) {
# $Full DirPath format is
\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup
my $SubName = &?ROUTINE.name;
my Str $RtnStr = RunCmd "powershell Test-Path $DirPath", True;
$RtnStr = $RtnStr.chomp;
if $CommandLine.debug { print "$SubName: powershell Test-Path
returned <$RtnStr> for <$DirPath>\n\n"; }
if $RtnStr.lc.contains( "true" ) { return True; } else { return
False; }
}
Oh ya, and the above actually works!
Forgive my being crabby. I have been coding on this project
for over a week. It was only suppose to take a day. I have
been CHASING GHOSTS. I am really, really tired. Now I have
to remove all of the IO calls from my code and replace them
with calls to powershell. AAAA HHHH !!!!!! At least I
have finally figured out what was going wrong.
Thank you for the help!
-T
From: Joseph Brenner
The Raku Study Group
"This time for sure!" -- Bullwinkle J. Moose
April 6th, 2025 1pm in California, 8pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/89759925908?pwd=59mwQboALSjiFQB9tdT2DDd4Xkxdi8.1
Passcode: 4RakuRoll
From: ToddAndMargo via perl6-users
And another IO ffunctio that does ot work:
RotateArchives: renaming directory
\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6 to
\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4
Failed to rename
'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup6' to
'C:\192.168.240.10\oldserver\Backup\MyDocsBackup\backup4': Failed to
rename file: no such file or directory
rename put a freaking C: on teh unc path.
Another call to powershell. Poop!
From: ToddAndMargo via perl6-users
On 4/2/25 9:53 PM, ToddAndMargo via perl6-users wrote:
> On 4/2/25 6:26 PM, Will Coleda wrote:
>> Try printing the Str before you do anything with it to see what happens.
>
>
> I moved to powershell
I mean I did a call to powershell to find if a directory existed
From: ToddAndMargo via perl6-users
On 4/2/25 6:26 PM, Will Coleda wrote:
> Try printing the Str before you do anything with it to see what happens.
I moved to powershell
From: ToddAndMargo via perl6-users
On 4/2/25 6:08 PM, Bruce Gray wrote:
>
>
>> On Apr 2, 2025, at 19:47, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
>
> --snip--
>
>> raku -e "say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1'.IO.d.Bool;"
>> False
>
> --snip--
>
> Moving this one-liner into a .raku file (to remove the complication of Windows needing double-quotes for our `-e`), and removing `.IO.d.Bool`, I ran just this line:
> say '\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1';
> The output is:
> \192.168.240.10\oldserver\Backup\MyDocsBackup\backup1
> So, the initial two backslashes are becoming a single backslash.
> You need a quoting that does not special-case doubled backslashes (like the Q[] I have seen you use), or to enter the path with initial quadruple backslashes.
>
> Does changing your one-liner to this:
> raku -e "say Q[\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1].IO.d.Bool;"
> fix the problem?
Yes.
raku -e "say
Q[\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup1].IO.d.Bool;"
True
raku -e "say
Q[\\192.168.240.10\oldserver\Backup\MyDocsBackup\backup10].IO.d.Bool;"
False
Now how do I encode a variable inside a Q[]?
> If not, remove the `.Bool` just for a test run. You might still get False (like if the path exists but is not a directory), or you might get a Exception that gives you more detail of what is going wrong (like `Failed to find ...`, with the exact path that it was *actually* looking for).
>
From: Bruce Gray
> On Apr 2, 2025, at 05:47, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
--snip--
> Hi Bruce,
>
> Sorry. I do know I am suppose to post some minimal code.
> I was programming for 11 straight hours and was not
> thinking too clearly.
I understand.
> I was trying to do what you said. Read it into a hash, then
> extract the values into an OOP structure. (I use to like
> hashes, but dropped them hard when I figured out OOP
> structures. I absolutely A-D-O-R-E OOP structures.)
>
> Thank you again for the help!
> -T
--snip--
> my $CommandLine = CommandLineClass.new{
> help => False,
> debug => False,
> UNC_BackupPath => Q[\\192.168.240.10\MyDocsBackup\backup1],
> rotates => 2,
> ParentDir => "/"
> };
The problem is with the syntax of the `new`.
You need parenthesis instead of curly braces.
With that change, your code works as expected.
For even DRYer code, you can flatten `%opts` directly into the `new` constructor, like so:
# use lib 'C:/NtUtil', 'C:/NtUtil/p6lib'; # use this one on customer machines
use Getopt::Long;
class CommandLineClass is rw {
has Bool $.help = False;
has Bool $.debug = False;
has Str $.UNC_BackupPath = Q[\\192.168.240.10\MyDocsBackup\backup1];
has Int $.rotates = 2;
has $.ParentDir = '/';
}
my %opts = get-options( 'help', 'debug', 'UNC_BackupPath=s', 'rotates=i', 'ParentDir=s' ).hash;
my CommandLineClass $CommandLine .= new( |%opts );
say $CommandLine.raku if $CommandLine.debug;
--
Hope this helps,
Bruce Gray (Util of PerlMonks)
From: Bruce Gray
> On Apr 1, 2025, at 03:55, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
--snip--
> I have the following run string:
> raku C:\NtUtil\RLA.Backup.raku --rotates 345 --UNC_BackupPath \\192.168.240.10\Backup\MyDocsBackup\backup1 --debug
>
>
> use Getopt::Long; # get-options
> get-options('debug' => $CommandLine.debug );
>
> error out with
> No such method 'debug' for invocant of type 'List'
>
> What am I doing wrong?
You are not giving us a https://en.wikipedia.org/wiki/Minimal_reproducible_example , so I am having to guess.
My guess is that you have defined `$CommandLine` in a way that lacks a writeable `.debug` method.
You *could* simplify the call to `get-options` to use a simple temp variables (similar to the documentation), then copy the temp into some `debug` and similar parts of your more complex `$CommandLine` data structure, but I expect your full code is trying to avoid such temp vars.
Here is a complete runnable program to demonstrate skipping any temp vars, using a wild guess that `$CommandLine` is the sole instance of a OO data class:
class CommandLineInfo {
has Bool $.debug is rw = False;
}
my CommandLineInfo $CommandLine .= new;
use Getopt::Long;
get-options( 'debug' => $CommandLine.debug );
say $CommandLine.debug; # Will be `True` or `False`, depending on command-line arg.
If this code does not align with (and is not adaptable to) your use case, we (or at least *I*) will need more information from you, especially the definition of `$CommandLine` in your current code.
As always, minimal *runnable* code will allow any of us to provide an answer to you more quickly.
FWIW, I use `sub MAIN`, but if I were to use `Getopt::Long`, I might use the (under-documented) method of having `get-options` build the data structure itself:
use Getopt::Long;
my %CommandLine = get-options( 'debug', 'rotates=i', 'UNC_BackupPath=p' ).hash;
say ?%CommandLine<debug>; # Just the `debug` argument, forced to Bool
say %CommandLine.raku; # All the specified arguments.
> Many thanks,
> -T
You are very welcome!
--
Bruce Gray (Util of PerlMonks)
From: ToddAndMargo via perl6-users
Should have said "I need help with get-options"
From: Joseph Brenner
Doug Hoyte, "Let Over Lambda-- 50 Years of Lisp" (2008):
"It must also be pointed out that aif and alambda, like all anaphoric
macros, violate lexical transparency. A fashionable way of saying this
is currently to say that they are unhygienic macros. That is, like a
good number of macros in this book, they invisibly introduce lexical
bindings and thus cannot be created with macro systems that strictly
enforce hygiene. Even the vast majority of Scheme systems, the
platform that has experimented the most with hygiene, provide
unhygienic defmacro-style macros-presumably because not even Scheme
implementors take hygiene very seriously. Like training wheels on a
bicycle, hygiene systems are for the most part toys that should be
discarded after even a modest level of skill has been acquired."
https://letoverlambda.com/index.cl/guest/chap6.html
The Raku Study Group
March 23, 2025 1pm in California, 8pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/81750169963?pwd=SY3gIr63jZtsXVgW4PDXwbOdLavt1c.1
Passcode: 4RakuRoll
From: Joseph Brenner
"There is no royal road to logic, and really valuable ideas can
only be had at the price of close attention. But I know that in
the matter of ideas the public prefer the cheap and nasty ... "
-- C.S. Pierce, "How to Make Our Ideas Clear" (1878)
The Raku Study Group
March 9, 2025 1pm in California, 9pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/85701010841?pwd=b6eclkW4hs35tWs8a4F7kJonKaxybe.1
Passcode: 4RakuRoll
From: Joseph Brenner
"I found my way in the dark by bouncing off of sharp objects,
as do we all." -- Algis Budrys
The Raku Study Group
February 23, 2025 1pm in California, 9pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/84661895479?pwd=f2QJ1XTaquo6JDbhNwuFalAqoDpHJ8.1
Passcode: 4RakuRoll
From: Joseph Brenner
"The term Baroque probably ultimately derived from the Italian
word barocco, which philosophers used during the Middle Ages to
describe an obstacle in schematic logic. Subsequently the word
came to denote any contorted idea or involuted process of
thought. ... In art criticism the word Baroque came to be used
to describe anything irregular, bizarre, or otherwise departing
from established rules and proportions."
Encyclopedia Britannica "Baroque art and architecture"
https://www.britannica.com/art/Baroque-art-and-architecture
The Raku Study Group
February 9, 2025 1pm in California, 9pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/82992902436?pwd=9HTor3l74UjrnEPVpzK9VnycTEGTEp.1
Passcode: 4RakuRoll
From: Joseph Brenner
"In my experience, the sweet spot is to implement new modules in a
_somewhat general-purpose_ fashion. The phrase 'somewhat
general-purpose' means that the module's functionality should
reflect your current needs, but its interface should not. ... The
word 'somewhat' is important: don't get carried away and build
something so general-purpose that it is difficult to use for your
current needs."
John Ousterhout, Stanford University
_A Philosophy of Software Design_ (2018)
The Raku Study Group
January 26, 2005 1pm in California, 9pm in the UK
An informal meeting: drop by when you can, show us what you've got,
ask and answer questions, or just listen and lurk.
Perl and programming in general are fair game, along with Raku,
Zoom meeting link:
https://us02web.zoom.us/j/86114142481?pwd=AQaWj8tiBdAfvN5law6FTYsD61GksT.1
Passcode: 4RakuRoll
From: Joseph Brenner
I've had to cancel the announced meeting on the 19th. The next Raku Study
Group is on January 26th. Hope to see you.
https://github.com/doomvox/raku-study
From: ToddAndMargo via perl6-users
On 1/16/25 1:41 AM, Todd Chester via perl6-users wrote:
> First I should apologize for one of my earlier posts. The first token
> was a bit of a jumble. I think now you just want the literal string
> "download" to start your capture.
Hi Bill,
Don't apologize. You are teaching me at trans
light speed (FLT or Faster Than Light, it is
coming to humanity soon). I sincerely appreciate
it.
I am still slowly reading over your post, bit by
bit, to make sure I completely understand it.
:-)
-T
From: Todd Chester via perl6-users
Thank you!
On 1/13/25 18:20, William Michels via perl6-users wrote:
> Hi Todd,
>
> First I should apologize for one of my earlier posts. The first token was a bit of a jumble. I think now you just want the literal string "download" to start your capture.
>
> As per usual I tried a few different approaches to your regex problem, and posted what I thought was the best one, However an older iteration crept into one of my email posts: it used `^` which is Raku's zero-width "start-of-string" regex token.
>
> If you use `^` you will capture from the start-of-string onward, in this case through the `.*?` any-character token and up to the \> angle. You may not want this as it actually means the word "download" isn't required for you to capture that sequence of characters.
>
> I'm not sure where you got the impression that `\...\` actually means anything specific in Raku. If you're asking for a match against alphanumeric characters in Raku you don't have to escape them. Anything else (e.g. punctuation) you'll have to escape. So this means if you're trying to match ">" the "greater-than" sign (angle), you'll have to escape it via a backslash (e.g. `\>`), or by quoting (e.g. ">").
>
> For non-alphanumeric characters, an unescaped punctuation characters is reserved for special "metacharacter" purposes: for example an unescaped "." dot means "any-character". You'll also note backslashing used to denote characters that are difficult to represent otherwise. Think for example how `\n` means newline, `\t` means tab. There are others: `\s` means whitespace, `\h` means horizontal-whitespace, and `\v` means vertical whitespace. Also `\S` means non-whitespace, `\H` means non- horizontal-whitespace, and `\V` means non- vertical-whitespace.
>
> I've also posted direct links to Raku regex forms, such as `<?before ... >` (a positive lookahead) and `<?after ... >` (a positive lookbehind). You can try this in the REPL:
>
> [0] > my $a = "XYZ"
> XYZ
> [1] > say $a ~~ m/ <?after X > Y <?before Z > /;
> ï½¢Yï½£
>
> Try reading that out loud in English, "say $a smartmatching against a requested `m` match comprising after-X, Y, before-Z". If you read it that way, you'll understand why only the `ï½¢Yï½£` ends up in the match variable. You can also `andthen` the smartmatch, which will put the match in the `$_` topic variable for you, which can help with stringification:
>
> [1] > $a ~~ m/ <?after X > Y <?before Z > / andthen put $_.Str;
> Y
>
> I'll try to go through and correct what you wrote below. Best, Bill.
>
>> On Jan 12, 2025, at 03:11, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
>>
>> Hi Bill,
>>
>> Please correct my notes.
>>
>> Many thanks,
>> -T
>>
>>
>>
>> Explanation:
>> my @y = $x ~~ m:g/ <?before ^ | download > .*? <?before \> | \h+ > /;
>>
>> `m:g` # match and global
> CORRECT
>> `\...\` # the constrains (beginning and end) of the match
> NO, backslashes are used to escape non-alphanumeric characters, denote invisible characters (e.g. `\n`), etc.
>> `<...>` # constraints of instructions inside the match
> NO, `<?after ... >` is a lookbehind and `<?before ... >` is a lookahead.
>>
>>
>>
>> First instruction: `<?before ^ | download >`
> NO, this should just be the literal string `download` (or `"download"`)
>>
>> `?download ^` # positive look-behind, match but don`t capture `download `
>> # `^` means "look behind"
>>
>> `|` # This is logical "OR"
>>
>> `download ` # positive look-behind, match but don`t capture `download `
>>
>> summary: capture everything behind `before ` or capture just `download`
>>
>>
>> Second instruction: `.*?`
>> `.*?` # any-character, one-or-more, frugal up to the third instruction
> YES, CORRECT
>>
>>
>> Third instruction: `<?before \> | \h+ >`
> NO, SIMPLIFY THIS TO `<?before \>` and the match will stop when it encounters ">" the "greater-than" sign (angle). Because you're using a lookahead (match characters and "lookahead" to find a pattern but don't capture, example ), the ">" angle doesn't get captured.
>>
>> `<?before \>` # positive look-ahead, match but don`t capture `download \>`
> KINDA, the actual construct is `<?before \> >` or (even more readable), `<?before ">" >`
>> # Note that the `\` in `\>` is escaping the `>` and is removing
> KINDA, the `\` backslash in front of a non-alphanumeric is a rule in Raku. If it isn't backslashed Raku will try to interpret the non-alphanumeric as a metacharacter.
>> # the `>` from the instructions constraints and making is part
>> # of the match
> The unescaped `>` is part of the lookahead/lookbehind construct, either `<?after ... >` (lookbehind) or `<?before ... >` (lookahead).
>>
>> `|` # This is logical "OR"
> YES
>>
>> `\h+ ` # one-or-more horizontal whitespace character
> YES
>>
>> summary: capture everything before `before` or one-or-more whitespace characters
> KINDA. Match the previous tokens, and stop matching when (before) you find one-or-more whitespace characters.
>>
>>
>
> HTH.
From: William Michels via perl6-users
Hi Todd,
First I should apologize for one of my earlier posts. The first token was a bit of a jumble. I think now you just want the literal string "download" to start your capture.
As per usual I tried a few different approaches to your regex problem, and posted what I thought was the best one, However an older iteration crept into one of my email posts: it used `^` which is Raku's zero-width "start-of-string" regex token.
If you use `^` you will capture from the start-of-string onward, in this case through the `.*?` any-character token and up to the \> angle. You may not want this as it actually means the word "download" isn't required for you to capture that sequence of characters.
I'm not sure where you got the impression that `\...\` actually means anything specific in Raku. If you're asking for a match against alphanumeric characters in Raku you don't have to escape them. Anything else (e.g. punctuation) you'll have to escape. So this means if you're trying to match ">" the "greater-than" sign (angle), you'll have to escape it via a backslash (e.g. `\>`), or by quoting (e.g. ">").
For non-alphanumeric characters, an unescaped punctuation characters is reserved for special "metacharacter" purposes: for example an unescaped "." dot means "any-character". You'll also note backslashing used to denote characters that are difficult to represent otherwise. Think for example how `\n` means newline, `\t` means tab. There are others: `\s` means whitespace, `\h` means horizontal-whitespace, and `\v` means vertical whitespace. Also `\S` means non-whitespace, `\H` means non- horizontal-whitespace, and `\V` means non- vertical-whitespace.
I've also posted direct links to Raku regex forms, such as `<?before ... >` (a positive lookahead) and `<?after ... >` (a positive lookbehind). You can try this in the REPL:
[0] > my $a = "XYZ"
XYZ
[1] > say $a ~~ m/ <?after X > Y <?before Z > /;
ï½¢Yï½£
Try reading that out loud in English, "say $a smartmatching against a requested `m` match comprising after-X, Y, before-Z". If you read it that way, you'll understand why only the `ï½¢Yï½£` ends up in the match variable. You can also `andthen` the smartmatch, which will put the match in the `$_` topic variable for you, which can help with stringification:
[1] > $a ~~ m/ <?after X > Y <?before Z > / andthen put $_.Str;
Y
I'll try to go through and correct what you wrote below. Best, Bill.
> On Jan 12, 2025, at 03:11, ToddAndMargo via perl6-users <perl6-users@perl.org> wrote:
>
> Hi Bill,
>
> Please correct my notes.
>
> Many thanks,
> -T
>
>
>
> Explanation:
> my @y = $x ~~ m:g/ <?before ^ | download > .*? <?before \> | \h+ > /;
>
> `m:g` # match and global
CORRECT
> `\...\` # the constrains (beginning and end) of the match
NO, backslashes are used to escape non-alphanumeric characters, denote invisible characters (e.g. `\n`), etc.
> `<...>` # constraints of instructions inside the match
NO, `<?after ... >` is a lookbehind and `<?before ... >` is a lookahead.
>
>
>
> First instruction: `<?before ^ | download >`
NO, this should just be the literal string `download` (or `"download"`)
>
> `?download ^` # positive look-behind, match but don`t capture `download `
> # `^` means "look behind"
>
> `|` # This is logical "OR"
>
> `download ` # positive look-behind, match but don`t capture `download `
>
> summary: capture everything behind `before ` or capture just `download`
>
>
> Second instruction: `.*?`
> `.*?` # any-character, one-or-more, frugal up to the third instruction
YES, CORRECT
>
>
> Third instruction: `<?before \> | \h+ >`
NO, SIMPLIFY THIS TO `<?before \>` and the match will stop when it encounters ">" the "greater-than" sign (angle). Because you're using a lookahead (match characters and "lookahead" to find a pattern but don't capture, example ), the ">" angle doesn't get captured.
>
> `<?before \>` # positive look-ahead, match but don`t capture `download \>`
KINDA, the actual construct is `<?before \> >` or (even more readable), `<?before ">" >`
> # Note that the `\` in `\>` is escaping the `>` and is removing
KINDA, the `\` backslash in front of a non-alphanumeric is a rule in Raku. If it isn't backslashed Raku will try to interpret the non-alphanumeric as a metacharacter.
> # the `>` from the instructions constraints and making is part
> # of the match
The unescaped `>` is part of the lookahead/lookbehind construct, either `<?after ... >` (lookbehind) or `<?before ... >` (lookahead).
>
> `|` # This is logical "OR"
YES
>
> `\h+ ` # one-or-more horizontal whitespace character
YES
>
> summary: capture everything before `before` or one-or-more whitespace characters
KINDA. Match the previous tokens, and stop matching when (before) you find one-or-more whitespace characters.
>
>
HTH.