Oneliner replace in-place adds extra spaces at the end of the file
1 direct reply — Read more / Contribute
|
by bliako
on Oct 26, 2025 at 16:04
|
|
|
Wise Monks,
I am doing an in-place replacement in a text file which succeeds but one (?) extra newline is added at the end of the file:
The input file (a):
1
2
3
The command:
perl -i -lp0e 's/2/4/gs' a
Output
1
4
3
# there is an extra newline at the end, above
Looping the above command (the replacement is done only the first time), will yield as many newlines at the end:
for i in $(seq 1 10); do perl -i.x -lp0e 's/2/4/gs' a; done
@@@@
bw, bliako
|
Why dot does not match newline in oneliner but it does in script, with /s modifier?
1 direct reply — Read more / Contribute
|
by bliako
on Oct 24, 2025 at 10:10
|
|
|
my $x = <<'EOX';
A {
B 123
C xyz
}
EOX
$x =~ s/A\s*\{.+?\}//s;
print "x='$x'\n"; # empty
but this does not (linux terminal):
perl -pe 's/A\s*\{.+?\}//s' <<'EOX'
A {
B 123
C xyz
}
EOX
# prints exactly what the input is
I have checked if there are mistaken shell interpolations to the oneliner script, but there are not, I think:
x='s/A\s*\{.+?\}//s'
echo $x
# s/A\s*\{.+?\}//s
Edit: the same problem if the oneliner operates on a file:
cat > infile<<'EOX'
A {
B 123
C xyz
}
EOX
perl -pe 's/A\s*\{.+?\}//s' infile
# or perl -i -pe 's/A\s*\{.+?\}//s' infile
|
Net::DNS::Paranoid and IPv6
1 direct reply — Read more / Contribute
|
by Corion
on Oct 23, 2025 at 03:57
|
|
|
Is there any IPv6-capable "paranoid" DNS resolver like Net::DNS::Paranoid, except with support for IPv6?
I'm currently writing a "link preview" fetcher, using Mojo::UserAgent. As this preview fetcher mildly implies fetching user-generated and/or user-controlled links (even though the application is primarily for myself), I'm looking for something like LWPx::ParanoidAgent / LWP::UserAgent::Paranoid / HTTP::Tiny::Paranoid, but for Mojolicious.
I have already resolved (hah!) myself to writing Mojo::UserAgent::Paranoid, which delegates (as they all do) the DNS resolution to Net::DNS::Paranoid, a DNS resolver class that blocks hosts and IP addresses that are unlikely
URLs for external services, especially localhost and other internal networks (192.168.*, 10.* and the multicast addresses).
This is all fine and good, if it weren't for IPv6. Net::DNS::Paranoid happily lets ::1 through, as the code mostly looks at IPv4 addresses and its DNS resolution also only speaks A records, not AAAA.
Simply adding ::1 (localhost in IPv6-speak) to the list of blocked hosts is a good start, but I would also want to block the multicast and link-local IPv6 addresses and some others. So, I'm mildly looking towards extending Net::DNS::Paranoid to also support IPv6, but maybe somebody has already done the work, or has links to an existing implementation in another language where I can crib the pitfalls and footguns from.
|
On which portable Strawberry Perl will Tk install?
1 direct reply — Read more / Contribute
|
by aplonis
on Oct 17, 2025 at 22:29
|
|
|
Might anyone know which archived version of portable Strawberry Perl, installable on Windows 11, will accept installation of Tk without jumping through patching hoops?
|
X11::GUITest and Umlauts
1 direct reply — Read more / Contribute
|
by LanX
on Oct 16, 2025 at 20:04
|
|
|
Hi
OS=Linux
I'm struggling to send special characters like umlauts ("äöüÄÖÜ") via X11::GUITest and SendKeys() to another
application.
Is there a trick I am missing? Anything after the first special character is discarded.
If I try the linux tool xte from the package 'xautomation', it works fine from the console:
gnome-text-editor & sleep 1; xte "str äöüÄÖÜß"
|
How do I build perl on Windows such that all "handshake" checks are avoided ?
3 direct replies — Read more / Contribute
|
by syphilis
on Oct 12, 2025 at 23:27
|
|
|
Hi,
I've often wondered whether, on Windows, *every* script that dies with a "handshake" error would actually have misbehaved if it had been allowed to continue.
If I had a build of perl that was identical, except that all "handshake" checks were avoided, then I'd be able to know ... and hence the question in the title.
(I'm fairly familiar with building perl on windows - no problems there. It's just a question of how to have a perl that doesn't run any of those pesky "handshake" checks.)
TBC, these "handshake" checks are the ones that result (upon failure) in the script aborting with a diagnostic of something like:
fu.c: loadable library and perl binaries are mismatched (got first handshake key 0000000012e00080, needed 0000000012d00080)
AFTERTHOUGHT:
I suppose I don't really need to avoid them. Just making them "non-fatal on failure" might suffice.
Maybe having them emit warnings, as opposed to actually croaking, might suffice.
However, it would also be nice to avoid having to hack the perl source.
Cheers, Rob
|
Weird performance issue with Strawberries and Inline::C
5 direct replies — Read more / Contribute
|
by Anonymous Monk
on Oct 12, 2025 at 15:06
|
|
|
2 C functions below differ in a single line marked with 3 stars. I thought that a modern decent compiler won't notice. I'm afraid I'm not qualified to analyse compiler flags differences. It's Win10, and 5.32 set-up long ago and portable 5.42 (PDL-edition) unpacked just now. (The code is about PWC-342-2, it's irrelevant and doesn't matter if it still returns valid answers after reduction to SSCCE). Have compiler optimisation settings been changed, in recent Strawberries, in what looks like wrong direction? (+ some more strange issues, but I'd better stay focused on this one)
use strict;
use warnings;
use feature 'say';
use Benchmark 'cmpthese';
use constant L => 1e5;
my $str = '1' x L;
substr $str, rand L, 1 , '0' for 1 .. L;
use Inline C => << 'END_OF_C';
int test_c_3( SV* str ) {
int i, tmp, acc, max;
STRLEN len;
char* buf = SvPVbyte( str, len );
len --;
acc = 0;
max = -2;
for( i = 0; i < len; i ++ ) {
acc += ( buf[ i ] == '1' ); // ***
tmp = i - 2 * acc;
if ( tmp > max ) max = tmp;
}
return max + acc + ( buf[ len ] == '1' ) + 1;
}
int test_c_4( SV* str ) {
int i, tmp, acc, max;
STRLEN len;
char* buf = SvPVbyte( str, len );
len --;
acc = 0;
max = -2;
for( i = 0; i < len; i ++ ) {
if ( buf[ i ] == '1' ) acc ++; // ***
tmp = i - 2 * acc;
if ( tmp > max ) max = tmp;
}
return max + acc + ( buf[ len ] == '1' ) + 1;
}
END_OF_C
say $^V;
say 'String length: ', L;
cmpthese -2, {
c3 => sub { test_c_3( $str )},
c4 => sub { test_c_4( $str )},
};
__END__
v5.32.1
String length: 100000
Rate c4 c3
c4 8800/s -- -0%
c3 8817/s 0% --
v5.42.0
String length: 100000
Rate c4 c3
c4 2511/s -- -71%
c3 8755/s 249% --
|
Test failures prevent installation of Module::Package::RDF (on CygPerl) ('Dependency Hell')
2 direct replies — Read more / Contribute
|
by Intrepid
on Oct 12, 2025 at 14:37
|
|
|
Here we go again, a pretty little problem with installing a CPAN module that I want to be on my system. The failure is with Module::Manifest::Skip, its tests won't get past the compile stage. The relevant message as appears below is Can't locate object method "_install_subs" via package "Module::Manifest::Skip". The failure was thrown at /usr/share/perl5/vendor_perl/5.40/Moo.pm line 49, so I updated Moo to release 2.005005 but that didn't solve the problem.
My system has these characteristics:
/usr/bin/perl v5.40.3
MS Windows 11
CYGWIN_NT-10.0-26100 3.6.4-1.x86_64 2025-07-15 07:55 UTC x86_64 Cygwin
@INC:
/usr/local/lib/perl5/site_perl/5.40/x86_64-cygwin-threads
/usr/local/share/perl5/site_perl/5.40
/usr/lib/perl5/vendor_perl/5.40/x86_64-cygwin-threads
/usr/share/perl5/vendor_perl/5.40
/usr/lib/perl5/5.40/x86_64-cygwin-threads
/usr/share/perl5/5.40
The following console output is a bit redundant but I wanted to be thorough:
Oct 12, 2025 at 18:37 UTC
|
WIn32::OLE debug
2 direct replies — Read more / Contribute
|
by Anonymous Monk
on Oct 11, 2025 at 08:41
|
|
|
I have the following code, which WORKS for a word file, but crashes for a similar word file (both docx)
use strict;
use Excel::Writer::XLSX;
use Spreadsheet::ParseXLSX;
use Carp qw( croak );
use Cwd qw( abs_path );
use Path::Class;
use Win32::OLE qw(in);
use Win32::OLE::Const 'Microsoft Word';
...
my $path=....;
my $word =Win32::OLE->new('Word.Application','Quit');
my $word_file = file(abs_path($path));
my $doc = $word->{Documents}->Open("$word_file");
print "after doc\n";
my $tables = $word->ActiveDocument->{Tables};
for my $table (in $tables) {
my $numrows=$table->Rows->Count;
$main::numcols=$table->Columns->Count;
# Iterate through rows and count columns
foreach my $rownum (1 .. $table->Rows->Count) {
my $row = $table->Rows->Item($rownum);# code crashes here
...
}
}
The code crashes as indicated with the message
Win32::OLE(0.1712) error 0x8002000e: "Invalid number of parameters"
in METHOD/PROPERTYGET "Item" at C:/Strawberry/perl/lib/Devel/ptkdb.pm line 2658.
When I try to debug with ptkdb it crashes as soon as I ask for a listing of $doc or $table
How do I go about debugging this??
|
Trouble writing a simple tracer using the DB package (loops endlessly)
1 direct reply — Read more / Contribute
|
by clueless newbie
on Oct 10, 2025 at 11:18
|
|
|
Greeting Monks,
I’m experimenting with using the built-in `DB` package to build a lightweight call tracer. I’ve previously done something similar using **Hook::LexWrap** and **Module::Info**, but this time I’d like to catch **entry and exit** events for subroutines directly through Perl’s built-in debugging interface.
Here’s the minimal prototype I’ve tried:
+
package Devel::Lite;
use strict;
use warnings;
use Time::HiRes ();
our $IN_TRACE = 0;
sub DB::sub {
return &$DB::sub(@_) if $IN_TRACE;
local $IN_TRACE = 1;
my $sub = $DB::sub;
my @args = @_;
print STDERR ">> entering $sub\n";
my @ret;
eval { @ret = &$sub(@args); };
print STDERR "<< leaving $sub\n";
die $@ if $@;
return wantarray ? @ret : $ret[0];
}
1;
Then I run it like this:
perl -I. -d:TobyLite -e "sub x { print qq{okay\n}; } x();"
…but it loops endlessly and never reaches my test sub.
If I insert a print inside the loop, I see repeated `"Time::HiRes::time"`, suggesting recursion into the debugger hook itself.
I’ve tried things like skipping `Devel::Lite` and `Time::HiRes` calls explicitly, and guarding with `$IN_TRACE`, but the loop persists.
What I’d like to understand is:
1. Why is `DB::sub` being triggered recursively despite the guard?
2. What’s the correct minimal pattern for tracing sub entry/exit safely?
3. Bonus: how best to distinguish user code from CPAN/core subs to keep the trace clean?
Environment:
This is perl 5.38.x built for MSWin32-x64-multi-thread
Running on Windows 10.
Any insight or examples would be appreciated — I’m not trying to build a full debugger, just a simple tracer that logs the call tree.
TIA
PS: So far this has stumped (in no order) ChatGPT, claude, and Gemini.
|