Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

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
7 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
2 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

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
CPAN module naming convention?
2 direct replies — Read more / Contribute
by sectokia
on Sep 03, 2023 at 22:37

    Hi monks, I want to add some modules I have made to CPAN. However I am unsure of what name they should be.

    Example: First I have wrapped 'AnyEvent::HTTP' with 'Promises' module to create a 'PromiseHTTP' module.

    Then I use that 'PromiseHTTP' module to create a 'PromiseDevice' module to talk to transact with a generic 'device' that other users may own.

    The question is what names should they be? Is it allowable to add modules under someone elses name space?

    What name should 'PromiseHTTP' be?

    AnyEvent::HTTP::Promise Promises::AnyEvent::HTTP Promises::HTTP HTTPEventPromises something else?

    Should the 'PromiseMyApi' module be:

    Devicename Promises::Device AnyEvent::HTTP::Promise::Device or Something else?

    Thanks!

Filehandles and CSV_XS
2 direct replies — Read more / Contribute
by Melly
on Sep 01, 2023 at 06:34

    Hi Monks

    I'm trying to understand the different behaviour of file-handles and similar (e.g. '<DATA>').

    I don't think I'd ever really thought about them - they just worked - but I ran into a problem with CSV_XS and getline. Basically, why does a FH variable work (e.g. $IN), but <IN> and <DATA> don't.

    The following code is non-functional without commenting out stuff, but should illustrate what I mean.

    use Text::CSV_XS; my $csv = Text::CSV_XS->new(); open(my $IN, '<', 'test.csv'); # ok open(IN, '<', 'test.csv'); # nope my $row = $csv->getline(<DATA>); # nope - Usage: Text::CSV_XS::getline +(self, io) at test_02.pl line 11, <IN> line 2. my $row = $csv->getline(<IN>); # nope - Usage: Text::CSV_XS::getline +(self, io) at test_02.pl line 11, <IN> line 2. my $row = $csv->getline($IN); # ok print ${$row}[0]; __DATA__ a,b,c d,e,f

    So, what is the difference between "open(IN..." and "open($IN..."? (and is there a way to alias <DATA> to, e.g., $DATA?)

    UPDATE

    Ah - \*DATA or \*IN - err, what does '\*' imply?

    map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
    Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk
Almalinux throwing Perl_xs_version_bootcheck undefined error
3 direct replies — Read more / Contribute
by stingray020
on Aug 31, 2023 at 07:14

    Greetings Perl Monks.

    I'm an occasional, though long-time Perl coder.

    On a CentOS shared hosting setup, I had a load of perl scripts reading and writing successfully to a Maria database using DBI.

    The hosting company, for good reasons, migrated the account to another server running Almalinux, and the above scripts broke. For a long time the hosting company blamed coding errors, which were apparently spontaneously created without human intervention when the account was migrated.

    I've spent quite a bit of time investigating and the core issue is that the following error is given (by redirecting STDERR to a text file), together with a 500 server error to browser, by the pared down code below (yes, the original code did have use strict, warnings, diagnostics, redirect to STDERR, db write, disconnect, and attempted to write to browser, among other features).

    usr/bin/perl: symbol lookup error: /home/username/perl5/lib/perl5/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so: undefined symbol: Perl_xs_version_bootcheck

    #!/usr/bin/perl use cPanelUserConfig; use DBI; our $dbpath = "DBI:mysql:valid_servername:localhost"; our $dbuser = "validUsername"; our $dbpass = "validPassword"; my $result = pushdata(); sub pushdata { my $dbh = DBI->connect($dbpath,$dbuser,$dbpass); 1; }
    See also this thread:

    https://forum.directadmin.com/threads/error-on-spamassassin-install.67667/

    On talking again with the hosting company, they've made further disclosures, stating that they are running Perl v5.26.3 where 'perl scripts and modules are not compatible or wont work'.

    Can the Monks share any enlightenment on whether backward compatibility in Perl is now lost and the format of DBI calls needs to change, or whether perhaps I should seek a different hosting company, among other possible solutions? Thanks in advance.

Why is my code producing weird output?
4 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 30, 2023 at 19:04
    Hello dear Monks!
    I have a file in the form of:
    nick 5 nick 10 george 2 peter 3 george 14 nick 20
    and I want to output:
    george:2,14 nick:5~~10~~20 peter:3

    I had an old script that used to work:
    use strict; use warnings; my %res; while (<>) { chomp; my ( $name, $rest ) = split /\t/; push @{ $res{$name} }, $rest; } for $a( sort keys %res ) { print "$a:". join( "~~", @{ $res{$a} } ); print "\n"; }
    Now it produces weird results, can you please help me fix it? Perhaps I introduced a bug at some point and now I can't get it to work.
    Current output (weird):
    ~~14ge:2 ~~20:5 peter:3
[Solved] Wrapping code in a sub causes an error I don't understand.
3 direct replies — Read more / Contribute
by davies
on Aug 30, 2023 at 17:16

    The file below, with two lines commented out, works as I expect.

    use strict; use warnings; package Sscce; use Getopt::Long; use Pod::Usage; my ($opt_help, $opt_man, ); # sub main { GetOptions( 'help' => \$opt_help, 'man' => \$opt_man, ) or pod2usage(-verbose => 1) && exit; pod2usage(-verbose => 1) && exit if defined $opt_help; pod2usage(-verbose => 2) && exit if defined $opt_man; # } 1; =pod =head1 NAME =head1 ARGUMENTS =head1 OPTIONS --help Brief manual --man Full manual

    Running the file gives the output below:

    X:\Data\Perl\NoFile>perl Sscce.pm -h Arguments: Options: --help Brief manual --man Full manual X:\Data\Perl\NoFile>perl Sscce.pm -m NAME ARGUMENTS OPTIONS --help Brief manual --man Full manual

    But if the two comment lines are uncommented and the calling command changed, I get an error:

    X:\Data\Perl\NoFile>Perl -I. -MSscce -e"Sscce::main @ARGV" -- -h Can't open -e: No such file or directory at Sscce.pm line 17.

    I fear that I have no idea how to approach this. Adding diagnostics gives more data:

    X:\Data\Perl\NoFile>Perl -I. -MSscce -e"Sscce::main @ARGV" -- -h Can't open -e: No such file or directory at Sscce.pm line 18 (#1) (S inplace) The implicit opening of a file through use of the <> filehandle, either implicitly under the -n or -p command-line switches, or explicitly, failed for the indicated reason. Usually this is because you don't have read permission for a file which you named on the command line. (F) You tried to call perl with the -e switch, but /dev/null (or your operating system's equivalent) could not be opened. Uncaught exception from user code: Can't open -e: No such file or directory at Sscce.pm line 18. Pod::Simple::parse_file(Pod::Usage=HASH(0x262f6a8), "-e") call +ed at C:/Strawberry/perl/lib/Pod/Text.pm line 737 Pod::Text::parse_file(Pod::Usage=HASH(0x262f6a8), "-e") called + at C:/Strawberry/perl/site/lib/Pod/Simple.pm line 535 Pod::Simple::parse_from_file(Pod::Usage=HASH(0x262f6a8), "-e", + GLOB(0x2623f40)) called at C:/Strawberry/perl/lib/Pod/Text.pm line 7 +06 Pod::Text::parse_from_file(Pod::Usage=HASH(0x262f6a8), "-e", G +LOB(0x2623f40)) called at C:/Strawberry/perl/lib/Pod/Usage.pm line 17 +9 Pod::Usage::pod2usage("-verbose", 1) called at Sscce.pm line 1 +8 Sscce::main(GLOB(0x2623f40)) called at -e line 1

    Unfortunately, going through the code points listed has left me none the wiser. I'd be grateful for any help.

    Regards,

    John Davies

How to author a module with optional XS
3 direct replies — Read more / Contribute
by NERDVANA
on Aug 30, 2023 at 15:49

    The usual pattern for optional-XS modules is to have one dist that is the pure-perl implementation and another dist that overrides the first with some XS speedups.

    This works, but often people list the pure-perl module as a dependency and then sometimes the XS one doesn't get installed for the average end-user, letting them suffer with low performance not realizing they could speed it up with an additional module.

    Has anyone explored the possibility of packaging the XS and PP together in the same dist so that the XS is compiled and installed iff a C compiler is available? Or even better, skips installing the XS if it fails to compile and install for any reason?

    I was toying with the idea, and thought a quick way to get there without a bunch of Makefile.pm shenanigans would be if I create a normal XS dist and then include that as a subdirectory of the PP dist. Then I just start a subshell to run the nomal make process in that subdirectory, and if it fails, I ignore it and continue installing and testing the PP module.

    Does anyone see any problems with that? Had this been solved better ways by other modules I could look at as an example?

Can't locate in @INC
6 direct replies — Read more / Contribute
by adrianstern
on Aug 30, 2023 at 11:20
    I'm tearing my hair out. I've been writing Perl since at least 2002. Suddenly on Monday evening I started getting this error on all my sites hosted on Freehostia:

    Can't locate lesenfantsterribles.pm in @INC (you may need to install the lesenfantsterribles module) (@INC contains: /usr/local/lib64/ perl5 /usr/local/share/ perl5 /usr/lib64/perl5/ vendor_perl /usr/share/perl5/ vendor_perl /usr/lib64/perl5 /usr/share/perl5)

    Adding a lib statement (use lib etc) makes no difference and the error is the same if the module is actually present in the directory or not

    Many of the sites have had no updates for years - 10 in one case. Freehostia say they haven't changed anything - what could be causing this. Permissions are unchanged and for the module vary from 0644 to 0755 - please don't ask why

    Any ideas what might have caused this to happen?
Writing my first module
6 direct replies — Read more / Contribute
by harangzsolt33
on Aug 30, 2023 at 00:35
    Greetings fellow monks!

    I have a bunch of questions about modules. Feel free to answer any of them or all of them. :)

    1. Do I need to put "use strict; use warnings;" at the top of my module? I don't see that in other modules, but why?

    2. Should I start the perl module with #!/usr/bin/perl or is it okay to leave this off?

    3. I think, I am going to write "use MyPackage;" in my perl program, and then myPackage.pm will be placed in my Perl's INC directory. Is this how it should be done? I mean, it works, but is this standard practice? I've seen some people write "require myPackage" but I don't know if I should use that. The difference between "use" and "require" isn't very clear to me. Since "use" is only 3 letters, that's why I thought I am going to use that one instead. lol

    4. I've noticed that some modules have "our $VERSION = ..." but I start my module with "my $VERSION" Is that okay?

    5. Btw what's the purpose of the $VERSION string? Is there a part of Perl that will try to access that value at some point during my program's execution?

    6. What if my module's name conflicts with another module that exists out there? Let's say I call my module something that does not exist in my INC directory yet, but then someone else also creates a module by the same name and it ends up overwriting my module at some point in the future when I download it? How do I prevent this? I want to create a module name that is short and easy to spell, but the problem is that most of the cool names are already taken.

    7. What if my module tries to achieve the same result that another popular module does but mine goes about doing it very differently? How should I name my module? My creativity has evaporated. I don't want to give the same name, because that's confusing. Do I make up a random name that has nothing to do with the program? I could call my module bat or ant or eagle, but that's not very descriptive. Lol

    8. Is it important to upload a module to CPAN, or can I just put it on my website and host it there? I know, if I die, my website will probably go offline, and CPAN will outlive me. But I still like my website better, because I have full control over it. The CPAN repository seems so convoluted. It's like a big maze to me.

    9. When I open some pm files in the INC directory, I notice that a lot of them seem to have plain text mixed with program code. The text or documentation is preceded by something like "=head1 DESCRIPTION" and I am not sure what this is. Is this standard practice? When I read the perl tutorial, I seem to have skipped this part. I don't remember what the "=" sign does. Is it like /* and */ in C language? Is there a program that makes it easy to read these inline documentations?

    10. Is it's okay if I put my documentation on simple comment lines started with "#" instead of "=" ?

    So, here is what I have so far:

    package MyPackage; $VERSION = "1.00"; my $PRIVATE = 444; # # DESCRIPTION: This function is just a test. # USAGE: myFunc() # sub myFunc { $PRIVATE++; print "\nPackage MyPackage::myFunc(@_)\nPRIVATE = $PRIVATE\n"; } 1;
LWP::Daemon barf on bad DNS
1 direct reply — Read more / Contribute
by MikeL
on Aug 29, 2023 at 21:35
    I have a Perl script that uses LWP::Daemon to accept requests via web URLs. Program works great under normal circumstances. However...

    I have a poor DSL connection that swamps easily, and just plain "farts" more than occasionally. When this happens, the next request will time out. The connection will come back within a minute or so, but in the meantime, my program will have crashed with:
    getnameinfo - Temporary failure in name resolution at /usr/share/perl5/HTTP/Daemon.pm line 182
    Line 182:
    $uri = $HTTP::URI_CLASS->new($uri, $self->daemon->url);

    I'm over my head here, I'm not finding the getnameinfo() call, it looks to me like it's basically just building a string.
    Can I just put a 'try' around it? I'd much rather lose this one msg than have the program do a 'die' like this.

    Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-09-06 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?