|
If you're new here please read PerlMonks FAQ and Create a new user.
|
Quests
|
Monk Quips Quest
Starts at: May 01, 2023 at 08:00
Ends at: Dec 31, 2023 at 18:59
Current Status: Active
|
8 replies
|
by erzuuli
|
Esteemed Monk kcott has recently proposed an excellent idea.
heretoforthwithstanding, we invite all monks to submit ideas for new monk quips!
Your quip suggestion should include the following details:
- Intended quip location: either XP Nodelet, Chatterbox, or Monkbar (that's the page header).
- Text of quip.
- Optional: background & foreground colours. If you include these, be sure they are nicely contrasting.
.
|
poll ideas quest 2023
Starts at: Jan 01, 2023 at 00:00
Ends at: Dec 31, 2023 at 23:59
Current Status: Active
|
4 replies
|
by pollsters
|
|
|
|
|
Perl News
|
A Roguelike in Perl Tutorials by Chris Prather
on Aug 08, 2023 at 05:19
|
1 reply
|
by ait
|
|
|
berrybrew version 1.40 released
on Aug 02, 2023 at 13:38
|
1 reply
|
by stevieb
|
I have released version 1.40 of berrybrew. It comes with some extensive changes over this, and the previous 1.39 version. (See the changes list).
User facing changes include:
- Ability to install and use the new 5.36 and 5.38 releases of Strawberry Perl
- berrybrew archives hidden command. It displays the list of portable Strawberry Perl zip files previously downloaded
- berrybrew download hidden command. Download, but do not extract the zip archive of a perl version
- berrybrew snapshot command. Export an installed perl version to a zip archive, and import a previous zip snapshot to a new installed instance
berrybrew snapshot usage:
- bb snapshot export <perl version> [snapshot name]
- bb snapshot import <snapshot name> [new instance name]
As far as changes on the developer side, the changes are significant. Here's a high-level list:
- Broke out like functionality in the main berrybrew.cs source file, and spread it across several new classes, each in their own source file
- Removed the deprecated berrybrew upgrade command. Upgrades shall be done via the installer
- Created a very extensive MANIFEST checking system for the installer. This ensures that all files that need to be installed are, those same files are removed upon uninstall, and no rogue files when building the installer are accidentally leaked in
- Added a significant amount of documentation for the development, build, test and release lifecycle of the project. If I get hit by a bus, I've created a fantastic roadmap for someone to carry on the project quite readily (bb dev docs)
- A few minor bug fixes, and one major one
-stevieb
|
|
|
Supplications
|
Mysteious hash problem
1 direct reply — Read more / Contribute
|
by BernieC
on Oct 16, 2023 at 10:05
|
|
|
my %dict ;
my $dict = "d:/perl/words.short" ;
open (my $wds, "<", $dict)
or die("Can't open wordlist: $!\n") ;
my $words = 0 ;
foreach my $wd (<$wds>)
{ $dict{$wd} = 1 ; }
say scalar keys(%dict) ;
say "got apple" if exists $dict{apple} ;
when I run it I get
D:\Perl>dictest.pl
66384
D:\Perl>
|
[XS] Manipulating the Stack
No replies — Read more | Post response
|
by syphilis
on Oct 16, 2023 at 01:40
|
|
|
Hi,
For this perl (Inline::C) script:
### try.pl ###
use strict;
use warnings;
use Inline C => Config =>
FORCE_BUILD => 1,
BUILD_NOISY => 1,
CLEAN_AFTER_BUILD => 0,
;
use Inline C => <<'EOC';
void foo(SV * x, ...) {
dXSARGS;
int i, ret = 0;
for(i = 0; i < items; i++) {
ret += (int)SvIV(ST(i));
}
printf("%d\n", ret);
XSRETURN(0);
}
EOC
# Apart from the building output, this script
# finally outputs -5 (== 1 + 2 + 3 - 11)
foo(1,2,3,-11);
Inline::C will generate the following XS file:
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "INLINE.h"
void foo(SV * x, ...) {
dXSARGS;
int i, ret = 0;
for(i = 0; i < items; i++) {
ret += (int)SvIV(ST(i));
}
printf("%d\n", ret);
XSRETURN(0);
}
MODULE = try_pl_22db PACKAGE = main
PROTOTYPES: DISABLE
void
foo (x, ...)
SV * x
PREINIT:
I32* temp;
PPCODE:
temp = PL_markstack_ptr++;
foo(x);
if (PL_markstack_ptr != temp) {
/* truly void, because dXSARGS not invoked */
PL_markstack_ptr = temp;
XSRETURN_EMPTY; /* return empty stack */
}
/* must have used dXSARGS; list context implied */
return; /* assume stack size is correct */
(That Inline.h file is automatically included. It's not used or needed in this case, and can be ignored.)
It's the PL_markstack_ptr dance with the temp pointer at the end that I'm particularly interested in - with an aim to avoiding it.
Some "void" functions will return nothing, others will return values off the stack.
Inline::C performs that dance to determine whether this void function is returning something, or whether it is "truly void".
I use Inline::C to generate quite a few XS files, and I'm hoping to avoid having to include this dance, especially since it started spitting out warnings in bleadperl recently (but since fixed).
It's not something you see in other XS files, and I figure it shouldn't be too hard to avoid.
The one thing I really don't understand is the need to restore the value of PL_markstack_ptr to the value held by temp (PL_markstack_ptr = temp;), prior to returning empty.
To date, I've had good success in removing this dance. For "truly void" functions that invoke dXSARGS (such as the given example), the implementation at the end of that XS file can be rewritten as
void
foo (x, ...)
SV * x
CODE:
PL_markstack_ptr++;
foo(x);
XSRETURN_EMPTY;
However, in this instance, PL_markstack_ptr has not been reset to the value it held prior to its incrementation.
Under what circumstances might that omission bite ?
I think (needs double checking) that, with the way I've constructed foo(), PL_markstack_ptr does need to be incremented - but I'd prefer not to perform that original dance if I don't have to.
UPDATE: Just double checked and found an instance of a very similar function that does require that PL_markstack_ptr is incremented.
Cheers, Rob
|
LICENCE file
2 direct replies — Read more / Contribute
|
by Bod
on Oct 15, 2023 at 16:42
|
|
|
I've added a LICENCE file following advice from SankoR in Re: GitHub perl-ci.yml
I have used App::Software::License as suggested in this Perl blog
However, both the blog and the module are quite old. Plus, the blog comment suggests this might not be the best methodology...
Is there a 'better' method that Monks are using?
As an aside, for the benefit of anyone stumbling this way looking at using App::Software::License. The documentation is wrong - at least for Strawberry Perl on Windows. The documentation shows single quotes for the --holder attribute. If single quotes are used, just the firstname is shown in the LICENCE file. Using double quotes solves this problem: --holder "Joe Bloggs"
|
Perl 5.36 warns for magic comparison
3 direct replies — Read more / Contribute
|
by hurricup
on Oct 15, 2023 at 06:34
|
|
|
According to the perldebguts:
Each array @{"_<$filename"} holds the lines of $filename for a file compiled by Perl. The same is also true for evaled strings that contain subroutines, or which are currently being executed. The $filename for evaled strings looks like (eval 34).
Values in this array are magical in numeric context: they compare equal to zero only if the line is not breakable.
But perl 5.36 warns in my debugger as: Argument "use v5.36;\n" isn't numeric in numeric eq (==) at
There is a simple comparison: if $lines[$lineno] == 0
Do I do something wrong?
|
bignum usage?
1 direct reply — Read more / Contribute
|
by rkd257
on Oct 14, 2023 at 23:44
|
|
|
I must be using bignum incorrectly, as I would have thought I would end up with 5 and 7 on the bottom 2 lines.
0.5833333333333333333333333333333333333333
5833333333333333333333333333333333333333
10000000000000000000000000000000000000000
use Math::BigRat;
use bignum;
my $cf = 1 - 1/6 - 1/4; ## $cf = 7/12
+ \
+
my $n = $cf->numerator();
my $d = $cf->denominator();
print "$cf\n";
print " $n\n";
print " $d\n";
|
Can two separate responses be sent to the client's browser from Perl, such as via fork{}?
2 direct replies — Read more / Contribute
|
by Polyglot
on Oct 14, 2023 at 23:01
|
|
|
I want to send a file to be downloaded via a "Save as..." type dialog in the client's browser. This requires a special set of HTTP headers. However, I would also like to update the requesting webpage at the same time, AJAX-style. Unfortunately, the two sets of headers must be different, and are not mutually compatible. My attempts so far have simply broken the file download, which is otherwise working.
Can I use a fork { ... } type of command to send back the file while still updating the webpage via AJAX? If so, how is this done? Which response should go back to the browser first, or does fork { ... } end up creating a race condition?
I'm not sure where to start looking for the direction to go with this, so any coding suggestions are welcome. Please note that I am not looking for a package--I have the downloading working already, and have learned to program the AJAX myself. I'm just needing to know how, if this is possible, to do both at the same time.
|
how Mojo::ua work with Net::Stomp
1 direct reply — Read more / Contribute
|
by Anonymous Monk
on Oct 14, 2023 at 04:41
|
|
|
I've an Mojo Useragent to connect a system to do regular tasks, and it works fine by far. Recently our R&D team introduce Stomp to do some long-live stuff. Since they use Java & JS, I have to implement it in perl by myself.
Below is some example code in JS:
var url = "ws://localhost:61614/stomp";
var client = Stomp.client(url);
function afterConnect(roomid) {
btn.addEventListener('click', function () {
var msg = input.value;
client.send(roomid, {}, msg);
}, false);
}
function createConnect(roomid, uid) {
client.connect(headers, function (error) {
if (error.command == "ERROR") {
console.error(error.headers.message);
} else {
afterConnect(roomid);
client.subscribe(uid, function (msg) {
var body = msg.body;
if (msg.headers['content-type'] == 'application/json') {
body = JSON.parse(msg.body)
}
});
}
});
}
......
......
The logic is simple, a local stomp client connect to server over websocket, then get data, modify data save data etc. What I confuse is,
I've searched Stomp on cpan, all modules about Stomp does not support WS, The Mojo::ua support WS (and async which why I prefer it), but doesn't support Stomp Protocol directly. Before I dig into Stomp protocol, is there a decent way to combine Mojo::ua and Stomp(Like Net::Stomp)? Thanks.
|
Is it possible at all to flush buffer and commit file write, if UTF-8 encoding is being used??
4 direct replies — Read more / Contribute
|
by dissident
on Oct 12, 2023 at 20:15
|
|
|
I was trying unsuccessfully half the day to find out how to make Perl flush and commit write of a logfile, for showing the progress on a web page.
This is my code:
sub printtolog
{
my $txt = shift;
my $logf;
$txt = getdirdatetag() . ': ' . $txt . "\n";
# see https://perldoc.perl.org/functions/open
open($logf, ">>:utf8", $logging_logfile)
|| die "$0: can't open $logging_logfile for appending: $!";
# see https://perldoc.perl.org/functions/select
# this does not work
# my $oldfh = select $logf;
# $| = 1;
# select($oldfh);
# this also does not work
# $logf->autoflush(1);
print $logf $txt;
# this does not work
# $logf->flush;
# $logf->sync;
# this also does not work
# $select()->flush();
# $select()->sync();
close $logf;
}
Finally, I found a comment on StackOverflow, saying that the UTF-8 encoding layer adds another buffering layer.
(See the discussion between Ikegami and Ωmega on https://stackoverflow.com/questions/33812618/can-you-force-flush-output-in-perl)
Is this the reason why the logfile only gets created and written after either writing some kilobytes of many messages, or when the program much later terminates?
Does there exist a way to circumvent this buffering and to force creation and flushing of the file at all?
|
GitHub perl-ci.yml
2 direct replies — Read more / Contribute
|
by Bod
on Oct 12, 2023 at 19:36
|
|
|
Whilst attempting to test a previous module, pryrt very helpfully introduced me to GitHub Continuous Integration.
I tried using this when I released WWW::Crawl and got lots of test configurations to pass, but others failed. When the tests ran again, different configurations passed and different configurations failed!
From this test run it seems much of the problem is from the $VERSION string. But this inconsistency is not reflected in the CPAN Testers results.
Is this an anomaly of GitHub Continuous Integration or have I got something wrong in the per-ci.yml file?
|
Increase verbosity of "make test"
3 direct replies — Read more / Contribute
|
by bliako
on Oct 11, 2023 at 03:04
|
|
|
Dear Monks,
I am trying to investigate failed tests which occur on some CPAN testers' systems but not in mine.
Without excluding other suggestions, I would like to make the command make test more verbose by not suppressing diag and STDERR output for each test. Right now, running make test I get:
...
t/11-scripts-pod.t .............................. ok
t/12-from-file.t ................................
...
Test Summary Report
-------------------
t/12-from-file.t (Wstat: 9 Tests: 11 Fail
+ed: 0)
Non-zero wait status: 9
Parse errors: No plan found in TAP output
So, I would like to know what's going in t/12-from-file.t and where exactly it gets KILL'ed. Alas the output is opaque.
I have read here https://stackoverflow.com/a/5307376 that running make test TEST_VERBOSE=1 will do exactly what I want.
The problem is I don't know how to tell CPAN testers to run make test TEST_VERBOSE=1 (and not the default make test).
The furthest I got was to add ANOTHER make test target in the produced Makefile, with increased verbosity flags, to be run after the usual make test via the MY::postamble technique (using ExtUtils::MakeMaker, e.g. see Re: Benchmarks target in Makefile). The caveat is that I am not sure it will go ahead if previous Makefile target has failed. I think it does not.
Is there a solution to this?
bw, bliako
|
PAR-Packer and IPC-Run
3 direct replies — Read more / Contribute
|
by izomiac
on Oct 10, 2023 at 07:38
|
|
|
I'm trying to produce an exe version of a script I've written and have run into trouble with the IPC::Run module. Both PAR::Packer and Perl2Exe produce errors with the code below:
#!/usr/bin/perl
#perl2exe_include "attributes.pm";
use strict;
use warnings;
$|=1;
use Symbol qw( gensym );
use IPC::Run qw( start );
use Tie::Handle;
use IPC::Run::Win32IO;
my %sp;
$sp{'STDIN'} = gensym();
$sp{'STDOUT'} = gensym();
$sp{'STDERR'} = gensym();
my $h = start
['./cnc.exe'],
'<pipe', $sp{'STDIN'},
'>pipe', $sp{'STDOUT'},
'2>pipe', $sp{'STDERR'}
or die "returned $?";
sleep 20;
PAR::Packer generates the following when I attempt to run the resulting .exe:
Inappropriate I/O control operation: Win32::Process::Create() at C:\Us
+ers\Izomiac\AppData\Local\Temp\par-4a6f7368\cache-6146a0a42031e00189f
+f49a355f90de7875866db\inc\lib/IPC/Run.pm line 2143.
Inappropriate I/O control operation: Win32::Process::Create() at C:\Us
+ers\Izomiac\AppData\Local\Temp\par-4a6f7368\cache-6146a0a42031e00189f
+f49a355f90de7875866db\inc\lib/IPC/Run.pm line 2244.
Inappropriate I/O control operation: Win32::Process::Create() at C:\Us
+ers\Izomiac\AppData\Local\Temp\par-4a6f7368\cache-6146a0a42031e00189f
+f49a355f90de7875866db\inc\lib/IPC/Run.pm line 2244.
And Perl2Exe runs the .exe version dozens of times simultaneously.
For context, this script launches a half-dozen other scripts and coordinates communication between them by piping things through STDIN/STDOUT. I adopted this approach since one subprocess is a Tk GUI, another loads gigabytes of data into memory, and another is a 32 thread genetic sorting algorithm, and combining them into one process caused all sorts of instability. This version is faster and much more stable, but it's a big ask to have end-users install perl.
Any suggestions or alternatives?
|
Extracting /regex/mg in a while loop
3 direct replies — Read more / Contribute
|
by NetWallah
on Oct 09, 2023 at 17:53
|
|
|
Esteemed Monks:
I'm looking for some recommendations/best practice/elegant solutions for the following (This code already produces the right results).
I was surprised by the fact that Method#2 (My original code) is SLOWER than Method#1.
use strict;
use warnings;
my $x= <<"__X__" x 4; # Increase multiplier for benchmarking
A data for A
B data for b
C data for c
__X__
# Method #1 - works but I don't like using $1,$2 - would rather use na
+mes
while($x=~/(^A|^B)(.+)$/mg){
print "$1 method1 $2\n"
}
# Method #2 -
open my $f,"<",\$x or die $!;
while(<$f>){
my ($name,$data) = m/(^A|^B)(.+)$/ or next;
print "$name method2 $data\n"
}
close $f;
# Method #3 (infinite loop)
#while(my ($name,$data)=$x=~/(^A|^B)(.+)$/mg){
# print "$name method3 $data\n"
#}
"These opinions are my own, though for a small fee they be yours too."
|
|
|
PerlMonks Discussions
|
Super Search confused?
1 direct reply — Read more / Contribute
|
by afoken
on Oct 15, 2023 at 20:56
|
|
|
Super-searching for rare words emits nonsense percentages and/or nonsense dates:
?node_id=3989;BIT=rhababer
Remainder of query was not run (used 10.01 seconds so far)
Found 0 nodes roughly between 2023-07-06 and 0 (searched 279.36% of DB).
where any text contains "rhababer"
Date: Author/owner: Title: Node type:
Press Next> to continue searching remaining 586.07% of DB.
Please be patient after submitting your search.
(Emphasis mine)
The search works fine, so the nonsense values are probably just cosmetic.
Update: Now that this node exists, the first result page works fine and lists this node. The next result page returns nonsense values:
Found 0 nodes roughly between 2019-08-25 and 0 (searched 739.47% of DB).
where any text contains "rhababer"
Date: Author/owner: Title: Node type:
Press Next> to continue searching remaining 122.21% of DB.
Please be patient after submitting your search.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
|
|
|
|