If you're new here please read PerlMonks FAQ and Create a new user.
Perl News
|
Coding in Perl? What support do you need?
on Jan 06, 2021 at 05:15
|
7 replies
|
by marto
|
Coding in Perl? What support do you need? over at the Perl foundation website has a linked survey:
"But think about this. If we switched Perl off today, there would be a problem. A huge problem! We know that Perl is the glue that holds a lot of the IT world together. The Perl Foundation wants to support the community to make sure that the IT world doesn’t fall apart and supporting people learning Perl is a big element of that.
We have developed a survey that needs just a few minutes of your time, to tell us what you would like, or need, to support your move into, or progress within, the Perl language."
|
Phishing Attack on CPAN Authors
on Jan 04, 2021 at 18:08
|
1 reply
|
by hippo
|
As announced by TPF. Take care, everyone.
|
|
Supplications
|
Unpacking byte stream long/quad little/big endian fields
1 direct reply — Read more / Contribute
|
by GrandFather
on Jan 21, 2021 at 19:54
|
|
I have a binary file (think ELF or Windows PE) that includes fields that may be long (32 bit) or quad (64) bit and little or big endien depending on the specific file. The script may be running on a big or little endian machine with a Perl built for 32 or 64 bits. I want to unpack the fields for later use that will include display using printf and file operations using read and seek so I need to convert from file representation to the running Perl's native representation for those fields. The following sample code does that, but the pack 'L2' ...; unpack 'Q' feels a bit clunky. Can it be tidied up?
use warnings;
use strict;
use Config;
use Fcntl;
printf "Perl $^V %s ivsize %d byteorder %d\n",
$Config{archname}, $Config{ivsize}, $Config{byteorder};
# Generate a "binary file" with a string of bytes likely to show up is
+sues in
# decoding
my $binary = "\x91\x34\x33\x90\x81\x32\x31\x80";
for my $fileLE (0, 1) {
my $fromFile = $fileLE ? 'V4' : 'N4';
open my $inFH, '<:raw', \$binary;
read $inFH, my $raw1, 4;
read $inFH, my $raw2, 4;
my $long1 = unpack $fromFile, $raw1;
my $long2 = unpack $fromFile, $raw2;
my $packed = pack "L2", $fileLE ? ($long1, $long2) : ($long2, $lon
+g1);
my $longlong = unpack 'Q', $packed;
printf "%s: %016x\n", ($fileLE ? "LE" : "BE"), $longlong;
}
A 32 bit Windows build prints:
Perl v5.32.0 MSWin32-x86-multi-thread-64int ivsize 8 byteorder 1234567
+8
BE: 9134339081323180
LE: 8031328190333491
A nice sanity check would be to run the code on a big endian system and see that the numbers generated are the same. Of course the long long processing will come unstuck where ivsize < 8.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
|
perl script to conda package
1 direct reply — Read more / Contribute
|
by jnarayan81
on Jan 21, 2021 at 11:51
|
|
Hi Monks, I'm curious if someone was trying to build a conda package of perl scripts/tools?
I tried to pursue this, but I failed ;(
https://docs.conda.io/projects/conda-build/en/latest/user-guide/tutorials/build-pkgs.html
Any suggestions or turorial links could help ...
|
let Makefile.PL to do the Readme file for me -- new target?
5 direct replies — Read more / Contribute
|
by Discipulus
on Jan 19, 2021 at 11:36
|
|
Hello folks!
Despite many years programming in Perl I'm at my second real module. I'm used to module-starter that uses ExtUtils::MakeMaker as default builder.
My laziness got suddenly annoyed to maintain a Readme file manually: I brutally copy my pod output to this file, but I must remember to do it anytime I modify the doc.
I supposed to automate this and I asked here and there. I was pointed to Overriding-MakeMaker-Methods where is stated:
> Here is a simple example of how to add a new target to the generated Makefile:
The only working (for my purpose) modification to my Makefile.PL is the following
sub MY::postamble {
return <<'MAKE_README';
postamble ::
$(PERLRUN) -MPod::Text \
-e "Pod::Text->new (sentence => 1, width => 78)->parse_from_file(
+qw( $(TO_INST_PM) Readme) );"
MAKE_README
}
Which modify the end of resulting Makefile generated by perl Makefile.PL from:
# --- MakeMaker postamble section:
# End.
to this:
# --- MakeMaker postamble section:
postamble ::
$(PERLRUN) -MPod::Text \
-e "Pod::Text->new (sentence => 1, width => 78)->parse_from_file(
+qw( $(TO_INST_PM) Readme) );"
# End.
Then I can succesfully run dmake postamble (yes strawberry perl has dmake) to have my Readme updated.
Questions
MY::postamble is a fixed name? Both the class MY and the postamble name are fixed? I tried different names and it always complains: dmake: Error: -- Don't know how to make `customname' Cannot the creation of the Readme integrated inside make dist or other similar steps?
Or should I treat Makefile.PL as a normal perl program putting my custom do_readme sub call before WriteMakefile one?
It's only me or the docs are sybilline and stingy of words?
PS I have chatted a bit on #perl channel about this and the discussion diverged on authoring tools (where ExtUtils::MakeMaker is not an authoring tool). mbtiny was suggested and also Distar with some interesting read: A-BRIEF-HISTORY-OF-AUTHORING and a COMPARISON
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|
Strange behaviour when regex variable is modified during match?
4 direct replies — Read more / Contribute
|
by rsFalse
on Jan 17, 2021 at 11:51
|
|
Hello.
Today I found a strange behaviour in my sandbox program after I tried to soft-code a variable. Here is my code:
#!/usr/bin/perl
use warnings;
use strict;
$\ = $/;
my $A = "1112"
# . ''
;
@_ = ( 'a' .. 'i' );
$A =~ /1+
(??{
print "[$&]";
$_ .= shift @_;
s!\B!shift@_!e;
print "\$_:[$_]";
})
$
/x;
|
Text::Summarizer fails on Windows 10
2 direct replies — Read more / Contribute
|
by Anonymous Monk
on Jan 16, 2021 at 13:21
|
|
Hello
I am trying to install on Windows 10, Strawberryperl v5.28.1, the module Text::Summarizer. I get the following - for my knowledge - strange error. Do you know what can I do to solve this issue?
cpanm Text::Summarizer
--> Working on Text::Summarizer
Fetching http://www.cpan.org/authors/id/F/FA/FAELIN/Text-Summarizer-2.
+01.tar.gz ... OK
Could not create directory 'C:\Users\TE\.cpanm\work\1610820965.16324\T
+ext-Summarizer-2.01\Corpus\written\newspaper:newswire' for 'Text-Summ
+arizer-2.01/Corpus/written/newspaper:newswire': mkdir C:\Users\TE\.cp
+anm\work\1610820965.16324\Text-Summarizer-2.01\Corpus\written\newspap
+er:.: Invalid argument; Die Syntax f³r den Dateinamen, Verzeichnisnam
+en oder die Datentrõgerbezeichnung ist falsch at C:/Strawberry/perl/l
+ib/Archive/Tar.pm line 819.
at C:\Strawberry\perl\bin\cpanm.bat line 132.
Could not extract 'Text-Summarizer-2.01/Corpus/written/newspaper:newsw
+ire' at C:\Strawberry\perl\bin\cpanm.bat line 132.
==> Found dependencies: Module::Build
Found Module::Build 0.4231 which doesn't satisfy 2.01.
! Installing the dependencies failed: Installed version (0.4224) of Mo
+dule::Build is not in range '2.01'
! Bailing out the installation for Text-Summarizer-2.01.
|
mysteries of regex substring matching
4 direct replies — Read more / Contribute
|
by smile4me
on Jan 15, 2021 at 16:42
|
|
We all know that "In list context, a regex match returns a list of captured substrings."
And, we also know "Numeric quantifiers express the number of times an atom may match. {n} means that a match must occur exactly n times."
So can the numeric quantifier work with the captured substrings?
perl -E '$s = q[AAD34017837201D98AAED18778DEF993];
say length($s), " ", $s;
@m = $s =~ /(....)(....)(....)(....)(.+)/;
say "", join("-",@m);'
# 32 AAD34017837201D98AAED18778DEF993
# AAD3-4017-8372-01D9-8AAED18778DEF993
In contrast, the following regex uses a numeric quantifier but does not work as above:
perl -E '$s = q[AAD34017837201D98AAED18778DEF993];
say length($s), " ", $s;
@m = $s =~ /(....){4}(.+)/;
say "", join("-",@m);'
# 32 AAD34017837201D98AAED18778DEF993
# 01D9-8AAED18778DEF993
So, is there a way to use capture groups to match multiple times like separate groups does in the first example?
|
How to display Tk window without waiting for user input
6 direct replies — Read more / Contribute
|
by Special_K
on Jan 15, 2021 at 15:56
|
|
#!/usr/bin/perl -w
use strict;
use Tk;
my $status = 0;
my $prev_status = 0;
my $mw = MainWindow->new();
$mw->withdraw();
while (1)
{
my $status = check_for_status();
if ($status != $prev_status)
{
# need to notify user but don't wait for click
$mw->messageBox(
-title => 'status changed',
-message => 'status changed',
-type => 'OK',
-icon => 'info',
);
}
$prev_status = $status;
}
I would like the window to display and also have the program keep executing, but currently the program waits for the user to click "OK". The windows are only intended to notify the user that the status variable has changed and no action is taken based on clicking OK to close the windows. I was not able to find a Tk window type that does not have some sort of dialog button that causes execution to wait for the user to click them.
I also considered somehow using fork() to spawn off each dialog window as a separate process, but exec() expects a system call. Is there an equivalent to exec() that accepts a block of perl code that I can use to spawn off each dialog window and have execution continue within the main loop? Status changes are relatively infrequent so I don't expect the computer to be swamped with open dialog boxes.
|
|
Cool Uses for Perl
|
A dice roller system with Marpa::R2
1 direct reply — Read more / Contribute
|
by Discipulus
on Jan 16, 2021 at 09:49
|
|
Hello folks!
I recently asked for your wisdom in First steps with Marpa::R2 and BNF and I got nice answers. I'm playing with dice in these days as you can see in the post is rand random enough to simulate dice rolls?. The module I finally crafted as toy project is Games::Dice::Roller (with its gitlab repository).
But I had a sudden desire to reimplement the whole in Marpa::R2 and evolvig duelafn's example and following precious GrandFather's suggestions I ended with the following working code.
I left in it a lot of debug messages in case someone comes here to look for Marpa::R2 examples.
It actually mimicry the beahaviour of my Games::Dice::Roller for input received (it still does not accept multistring arguments like 3d6 4d4+1 12 kh as the module does) and it outputs in the same way 3 elements: the result, a descriptive string and the internal datastructure.
The following code is different from Games::Dice::Roller because it has less constraints in received inputs: for example it accepts something like 6d4r1kh3+3 and computes also a correct result, but messing the description. My mudule would reject an input like this.
Possible inputs given as argument of the program:
3d6 # simplest one
3d6+3 # with a result modifier
3d8r1 # reroll and discard any 1
3d8rlt3 # reroll and discard any lesser than 3
3d8rgt6 # reroll and discard any greater than 6
3d8rgt6+2 # reroll and discard any greater than 6 and add +2 to the f
+inal result
4d6x1 # explode (a new roll is done) each 1 rolled
4d6xlt3 # explode lesser than 3
4d6xgt4 # explode greater than 4
4d12kh3 # keep highest 3 rolls
4d12kl3 # keep lowest 3 rolls
4d12dh3 # drop highest 3 rolls
4d12dl3 # drop lowest 3 rolls
4d20kh3+7 # keep hishets 3 rolls then add 7
Alea iacta est!
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|
|
|
|