The Perl Regexp Engine of course. I have been working hard on working out how to
formulate a regular expression with a negative lookbehind and I cannot get it right.
What I have right now is this: /^(?<!XDG_) [_A-Z0-9]+ _PATH$/x
I'll explain in english what I need. There will be desired matches with strings
like PKG_CONFIG_PATH but I must not match
XDG_SEAT_PATH or XDG_SESSION_PATH.
Naturally, it is not as simple as avoiding any match with a string beginning with
XDG_ because I want to match
XDG_DATA_DIRS, for example. (Yes, these are well-recognized
environment variables).
This works for getting only PATH: /^(?<!XDG_)PATH$/, so I can see that
the Engine does understand the lookbehind. Any suggestions will be appreciated!
Aug 22, 2025 at 13:49 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)
|
Given the recent licensing hokey-cokey by Redis I'm inclined to use Valkey in preference. However, there isn't any explicit mention of Valkey on CPAN that I could find. This isn't a huge surprise given how relatively new it is but nor does it give me confidence about support for it now or in the future.
So, does anyone have experience with using any of the various Redis modules with Valkey as the server? Is it as much of a drop-in replacement as I would hope?
|
I have XML that I manipulate and save.
Among other tags, I may have a <body> tag with simple text in it. XML::Smart insists on encoding that in this way:
<body dt:dt="binary.base64">
which causes an error since dt is not defined and I am not interested in defining it.
Is there a way to tell XML::Smart to NOT encode that tag.
XML::Smart proves to be to smart in this case
Thank you
ZA
|
Hello dear fellow nuns and monks!
While researching for a encoding problem, I wanted to retrieve the value of the current windows ANSI code page.
This can be done e.g. with Powershell like this:
Get-WinSystemLocale | Select-Object -ExpandProperty TextInfo | Select-Object -Property ANSICodePage
which gives the following output:
ANSICodePage
------------
1252
Instead of calling PowerShell and parsing its output, I tried to use Perl's own facilities.
perl -MWin32 -we "print Win32::GetACP()"
which however gave the following output:
65001
indicating an UTF8 ANSI code page instead of Western-Europe one (cp1252) from above.
I am using Strawberry Perl 5.38.0 64-bit with its own W32 module running on Windows 11.
Is this behavior understood and known? Did I miss something or could it be a bug?
Thanks very much for your attention!
|
Somewhere in a script that has turned all UTF8 flags on, Perl seems to get confused.
No matter what I try, it destroys the encoding when writing the data to a file, by writing two characters for every Unicode byte.
Thus most Unicode characters become a 4-byte, 2-character near-random looking string.
Could the UTF8 flag be not set where it should be set?
As it is apparently impossible to reliably check the UTF8/Latin state of a string variable, the best solution might be just to set the UTF8 flag when the data is known good UTF8.
So, is there a function or some reliable technique to set the UTF8 flag?
Or could it maybe be a better idea in those cases to write the file as raw binary data instead, to circumvent unwanted conversions?
Any other idea what to do?
|
I have an internal module that I include in all my scripts. I have been treating it as an optional dependency by loading it like so BEGIN { eval { require Internal::Module } }. This allows me to share my scripts and not have to worry about the internal module not existing on the users' system. But now I'm thinking it would be easier to manage by removing the extra boilerplate and including the module via the env var like so: export PERL5OPT="-MInternal::Module". This only works if the module exists, but I also need it to work if it does not exist. I've been playing around with the if module but haven't been able to get it to work for this case. Is it possible to do what I want?
|
Log4perl: Seems like no initialization happened. Forgot to call init()
+?
23:28:21 Sent 'Target.closeTarget' message $VAR1 = '{"id":11,"params":
+{"targetId":"F75959D2137237798CF1FCB89E87FFAA"},"method":"Target.clos
+eTarget"}';
23:28:21 Can't call method "irand" on an undefined value at (eval 140)
+ line 17 during global destruction.
As an example, consider the following test-script. For me, the below script sometimes passes and sometimes it fails (see below for when exactly), although all subtests succeed all the time.
#!/usr/bin/env perl
use Test::More;
use WWW::Mechanize::Chrome;
use Log::Log4perl qw(:easy);
# This is for the mech obj, Set priority of root logger to ERROR
Log::Log4perl->easy_init($ERROR);
my %default_mech_params = (
headless => 1,
# log => $mylogger,
launch_arg => [
'--window-size=600x800',
'--password-store=basic', # do not ask me for stupid chrome ac
+count password
# '--remote-debugging-port=9223',
# '--enable-logging', # see also log above
'--disable-gpu',
'--no-sandbox',
'--ignore-certificate-errors',
'--disable-background-networking',
'--disable-client-side-phishing-detection',
'--disable-component-update',
'--disable-hang-monitor',
'--disable-save-password-bubble',
'--disable-default-apps',
'--disable-infobars',
'--disable-popup-blocking',
],
);
my $mech_obj = WWW::Mechanize::Chrome->new(%default_mech_params);
ok(defined($mech_obj), "WWW::Mechanize::Chrome->new() : called.") or B
+AIL_OUT("failed to create WWW::Mechanize::Chrome object");
done_testing();
Here is what it says when I run make all && make test. Note that this fails all the time.
Manifying 1 pod document
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H
+arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l
+ib', 'blib/arch')" t/*.t
t/xx.t .. 1/? Log4perl: Seems like no initialization happened. Forgot
+to call init()?
2025/08/11 23:40:43 Sent 'Target.closeTarget' message $VAR1 = '{"metho
+d":"Target.closeTarget","id":11,"params":{"targetId":"FF3672A330F5788
+556F1B4B18CCC5610"}}';
2025/08/11 23:40:43 Can't call method "irand" on an undefined value at
+ (eval 140) line 17 during global destruction.
t/xx.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed
Test Summary Report
-------------------
t/xx.t (Wstat: 65280 (exited 255) Tests: 1 Failed: 0)
Non-zero exit status: 255
Files=1, Tests=1, 11 wallclock secs ( 0.03 usr 0.00 sys + 0.41 cusr
+ 0.12 csys = 0.56 CPU)
Result: FAIL
Failed 1/1 test programs. 0/1 subtests failed.
make: *** [Makefile:873: test_dynamic] Error 255
However, when I run make all && perl -Iblib/lib t/xx.t, sometimes it fails with above complaining and sometimes it succeeds.
I use the latest W:M:C v0.73. It fails with perl v5.40.2. On another computer with perl v5.38.2 I see no failures (after 10 consecutive runs). Both running latest linux.
Thanks, bw, bliako
ps. my question is not urgent, don't stop swimming to answer it...
ps2. OT but Corion does the dreadful Log4* abomination Log::Log4perl need to be used by WWW::Mechanize::Chrome?
|
Dear monks,
I want my perl program to sort just like the system it is running on.
This is trivial on Linux, but somehow seems complicated on Windows and macOS.
I use the following test program
#! perl
use strict;
use warnings;
use utf8;
binmode STDOUT => ':utf8';
my @words = ( "Maria Lenore", "Mária Helena", "María Dolores" );
my @sorted = sort @words;
if ( "@sorted" eq "María Dolores Mária Helena Maria Lenore" ) {
print("Sorted OK\n");
}
elsif ( "@sorted" eq "Maria Lenore María Dolores Mária Helena" ) {
print("Sorted C (ASCII)\n");
}
else {
print("Sort failed: @sorted\n");
}
On Windows, I get
PS C:\Users\Johan> perl locale.pl
Sorted C (ASCII)
PS C:\Users\Johan> perl -Mlocale locale.pl
Sorted C (ASCII)
PS C:\Users\Johan>
Same on macOS.
When I create files with names "Maria Lenore", "Mária Helena" and "María Dolores" they sort correctly in the Explorer (Windows) and Finder (macOS).
How can I have perl use the same sort order as the system?
Windows 10 with Strawberry Perl 5.30
MacOS 10.15 with Perl 5.34.
These versions are a bit old, but I can not imagine I'm the first to try such a sort in 25+ years.
|
With ExtUtils::MakeMaker, I would like to set the title of my manpage using pod2man's "--center" option. Unfortunately I cannot figure out how to do this. I have read through Makemakers doumentation but cannot find any mention of passing custom flags to pod2man. I noticed that in MakeMaker's outputted Makefile, there is a rule "manifypods" that handles creating the manpages with pod2man. However, I cannot figure out how to customize this rule. I noticed that pod2man is executed via a function "ExtUtils::Command::mm::pod2man, that does allow passing options, but I'm unsure of how I can gain control of this functions invocation.
Does anybody know how I can do this? Does anybody know of any other projects that pass custom options to pod2man from ExtUtils::MakeMaker?
|
I'm sure this is going to be really basic, but I've gone several decades using Perl and never needed the pack or unpack functions before.
#!/usr/bin/perl
use strict;
use warnings;
#
my $pReqsca = "ABCD";
my @bytary = unpack 'C*', $pReqsca;
+
my $binstr = '';
+
foreach my $scabyt (@bytary) {
+
my $intbyt = int($scabyt);
+
my $hexbyt = sprintf("%02X", $intbyt);
+
my $binbyt = unpack 'b8', $scabyt;
+
$binstr .= $binbyt;
+
print " Byte = [$scabyt] Integer = [$intbyt] Hex = [$hexbyt] B
+inary = [$binbyt] Binary String = [$binstr]\n";
print "Aborting Loop\n";
last;
}
Results:
W:\Steve\PerlMonks>perl sopw-584100.pl
Byte = [65] Integer = [65] Hex = [41] Binary = [01101100] Binary
+ String = [01101100]
Aborting Loop
Same results using 'B8',
Last time I checked, Hex 41 should show binary 01000001.
What am I missing here?
|