Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Seekers of Perl Wisdom

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

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask.

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

Post a new question!

User Questions
Perl equivalent of Watir
5 direct replies — Read more / Contribute
by Galdor
on Oct 15, 2021 at 06:31
    I've been given some web scraping tasks - Found Watir but I would rather use existing Perl experience than learn Ruby from scratch: I would like the solution to integrate with Chrome + brwoser automation, and some Perl Framework like Mojolicious. Any tips to get me started?
my within brackets
6 direct replies — Read more / Contribute
by Bod
on Oct 14, 2021 at 13:19

    I've come across this bit of code within an existing legacy script - not written by me

    (my $pname,my $sname)=split / +/,$rname,2;

    I'm wondering if it is functionally different to writing

    my ($pname, $sname) = split / +/, $rname, 2;
    I've tested the two against each other and they seem to behave exactly the same. But, is there some subtle difference my quick test has not uncovered?

Problem with regexp to match
5 direct replies — Read more / Contribute
by logangha
on Oct 14, 2021 at 11:18


    I have this assignment

    When a string comes with below content


    It must take numbers 13, 1, 14 and 1, in order as indicated

    And with this instruction is achieved

    perl -le '@m = ( "01/LC-13/E10GbE-1,01/LC-14/E10GbE-1" =~ /./\w+-(\d+) +/\w+-(\d+)(?=,./\w+-(\d+)/\w+-(\d+))/); print for @m'

    But when string comes with


    It must take numbers 13 and 1

    And when I run my example does not work

    $ perl -le '@m = ( "01/LC-13/E10GbE-1" =~ /./\w+-(\d+)/\w+-(\d+)(?=,./ +\w+-(\d+)/\w+-(\d+))/); print for @m'

    It does not return anything

    Which seems to be the trouble?

    I don't know much about regular expressions


Chrome freezes on windows when opened with WWW::Mechanize::Chrome
2 direct replies — Read more / Contribute
by bakiperl
on Oct 14, 2021 at 11:02
    My WMC scripts have suddenly stopped working on windows, but they still work fine on Linux. I am not sure if it was caused by the windows updates or the recent module updates. I hope Corion can check this.
    Here is a simple script that causes the freezing of the browser. It has been tested on 3 different machines and the result is the same.
    #!/usr/bin/perl -w use strict; use warnings; use 5.012; use WWW::Mechanize::Chrome; use Log::Log4perl ':easy'; Log::Log4perl->easy_init($TRACE); my $mech = WWW::Mechanize::Chrome->new( headless => 0, ); use Data::Dumper; my $res = $mech->get(''); say Dumper $mech->getResourceTree_future()->get; $mech->sleep (20);
Escape user name and password in LWP proxy call.
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 14, 2021 at 05:52

    Hi Monks, What is the best way to escape special characters like @, in username and password which is passed to the ua->proxy while using LWP::Useragent.
    I tried using URI::escape but it doesn't seem to be working.
    Thank you.

perl v5.28.1 install GPIB module fail
3 direct replies — Read more / Contribute
by jianfeng
on Oct 14, 2021 at 04:51
    I'm a new guy on perl, trying to install the below module on my windows10 64-bit OS, but fail. ActiveState Perl:v5.28.1 I also have copied the nmake into C:\VC6\Bin;

    please help me! thanks.

    C:\Users\jixi>cd C:\Perl64\cpan\build\gpib-0.30-0 C:\Perl64\cpan\build\gpib-0.30-0>perl Makefile.PL Use of uninitialized value in pattern match (m//) at C:/Perl64/site/li +b/ExtUtils/ line 40. Use of uninitialized value in pattern match (m//) at C:/Perl64/site/li +b/ExtUtils/ line 41. Use of uninitialized value in pattern match (m//) at C:/Perl64/site/li +b/ExtUtils/ line 42. Using interfaces: ni rmt Using instrument drivers: hp33120a hp3585a hp59306a hpe3631a Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Writing MYMETA.yml and MYMETA.json Use of uninitialized value $m[8] in join or string at C:/Perl64/site/l +ib/ExtUtils/ line 365. Generating a dmake-style Makefile Writing Makefile for GPIB Writing MYMETA.yml and MYMETA.json C:\Perl64\cpan\build\gpib-0.30-0>nmake Microsoft (R) Program Maintenance Utility Version 6.00.8168.0 Copyright (C) Microsoft Corp 1988-1998. All rights reserved. **to undefined at C:/Perl64/site/lib/ExtUtils/ line 141. NMAKE : fatal error U1077: 'C:\"Perl64\bin\perl.exe"' : return code '0 +xff'** Stop.
    Discipulus added code tags
Errors uncaught by CGI::Carp
2 direct replies — Read more / Contribute
by Bod
on Oct 13, 2021 at 16:46

    This is a follow on from the second part of the question I asked in CGI::Carp fatalsToFile
    The collective wisdom of The Monastery solved the first issue but not the seems they are unrelated!

    I am getting 500 errors intermittently from most, if not all of the pages of a website. The errors seems to be clumped together over time. In other words, once an error happens it seems likely that it will happen again quite soon. Whereas at other times we go quite a while without errors.

    Every script has use CGI::Carp qw(fatalsToBrowser); at the start of the script.
    The bit I am most confused about is that my understanding is that, with fatalsToBrowser the only two ways to get a 500 error is that the script has the wrong permissions or that the script doesn't return valid HTTP headers. As this is an intermittent problem, it is neither of these.

    This is the code of the modules that are common :

    package Site::HTML; use strict; use warnings; use DBI; #use DBD::mysql; use Exporter; use Template; use MIME::Lite; use Digest::SHA qw(sha256_base64); use cPanelUserConfig; use Site::Variables; use Bod::CRM; our @ISA = qw(Exporter); our @EXPORT = qw(%data %file %cookie $dbh $current_user); our $site = $Site::Variables::site; our $template = Template->new( INCLUDE_PATH => $Site::Variables::template_path, PRE_CHOMP => 0, POST_CHOMP => 1, ); our (%data, %file, %cookie, $dbh); our $current_user = 0; my $crm = Bod::CRM->new($Site::Variables::env_crm_env); # Untaint ENV{PATH} for MIME::Lite my $path = $ENV{'PATH'}; $ENV{'PATH'} = undef; foreach my $p(split /:/, $path) { if ($p =~ m!^(/(usr|bin).*)!) { $ENV{'PATH'} .= ':' if $ENV{'PATH'}; $ENV{'PATH'} .= $1; } }
    package Site::Wayfinder; use strict; use warnings; use cPanelUserConfig; use Digest::SHA qw(sha512_base64); use Facebook::Graph; use GD; use Bod::CRM; use Site::HTML; use Site::Point; my $crm = Bod::CRM->new(Site::HTML->crm_env); sub new { my $class = shift; my %attrs = @_; $attrs{'error'} = ''; $attrs{'fb'} = Facebook::Graph->new( app_id => '12345678', secret => 'abcdefghijklmnop', postback => "https://$ENV{'HTTP_HOST'}/?command=authori +ze_facebook", ); return bless \%attrs, $class; }
    I have commented out use DBD::mysql; because on one occasion I got some output from CGI::Carp that showed an error on that line. I have not been able to replicate this error. Not specifying a DBD driver forces DBI::DBD to use the driver in it's config which is setup to connect to the MariaDB database.

    My only hunch is that, because errors seem more concentrated at certain times, it is connected with the number of concurrent users. This in turn makes me wonder if is is Facebook::Graph that is the problem as it is deprecated. We only use Facebook for authentication. Users can create an account using Facebook rather than creating a password or can sign into an existing account using Facebook provided the email addresses are the same. This works under normal circumstances.

    It isn't just web browsers that are getting the error. Facebook is complaining that our privacy policy page is giving errors and Stripe gets occasion webhook errors.

    I am unable to replicate the problem on our test site - it only seems to happen on the live production site. Therefore I am limited on how much I can test or what I can tweak!

    Any ideas what I can do to try and get some understanding of what is going on?

    UPDATE: - to test my hunch that it is to do with multiple users, I have tried to cross referencer 500 errors with the data collected by Google Analytics and Hotjar. But the errors are not written to the Apache error log so this is proving difficult. I have started having Google Analytics open when I access the site so that I can look at the real time data when I next see an error.

iterating over time with DateTime to obtain values with Astro::Coords
5 direct replies — Read more / Contribute
by Aldebaran
on Oct 12, 2021 at 20:53

    Been a while since I have posted as OP with the Perlpocalypse and all. I took a tour "out there" to see what else was going on. I worked a bit with python, but, as a guy who started comp sci in the punchcard era, I can't look at fixed form source and call it "progress." (Do they have pythontidy like we have perltidy?)

    I also took a gander at Usenet. It was nice to see some old names, but it has the same cooties of spammers and pornographers that mutate faster than one's killfile. comp.unix.programmer was still viable, as well as comp.lang.fortran, but I couldn't figure out the proprietary client the provider wanted me to use, so that fizzled out. (That's a nice way of saying I got locked out of my own account with failed attempts.)

    I've had several scripts that I've been fiddling with in the meantime. This one came up in the context of Moon phase on historical events. I present attempts to iterate over the closed interval of a lunar cycle within the methodology of DateTime. It's not complete, but I've got output I don't understand, so I want to put it up for review. Let me just get source out there first:

    $et is to be the second at which the moon and venus conjoin, ie, have the same right ascension. The problem is that I check the data with John Walker's Fourmilab ephemeris and use the option for univeral time. The time defined in perl thus:

    my $isostr = '2021-10-09T11:13:57';

    is inputed without the T, and with the radio button activated, thus:

    2021-10-09 11:13:57

    But that's not our value to check, which should be $et, namely:

    2021-10-09 20:25:46

    It would seem that the moon is well past Venus by the margin of almost 2 hours. I tried to spitball if it might be using a different idea of coincidence with non-point masses. The full moon is about a half a degree. It's certainly not half full, and the dark edge hits venus first. In the prelims, I calculated that angle the moon moves through in a day to be 12.2 degrees. A quarter of a degree takes the moon about a half hour. Our answer seems to be at least 3 times out of this range as fourmilab has the conjunction between this interval, I:

    2021-10-09 18:30:00

    And this time:

    2021-10-09 18:40:00

    Q1) Do these bodies conjoin at $et or in the interval I? How does perl represent the moon in Astro::Coords? (For example, is the right ascension that of the center?}

    I didn't expect $phases[0] to be negative. Given that it was defined by

    my @phases = phasehunt($dt);

    Q2) How do I take $dt and $phases[0] and get epoch time?

    Q3) How do I get the duration of the program run to display correctly? I thought I followed Dave Rolsky's example.

    I wanted to be able to calculate the duration of the transit of the moon from venus to jupiter before it happened.

    Thanks for comments,

Seeking help with HTTPS form upload.
3 direct replies — Read more / Contribute
by FeistyLemur
on Oct 12, 2021 at 18:16

    >Greetings, I am attempting to reconstruct a post (using WWW::Mechanize and LWP::UserAgent so far) in order to upload a file and navigating some things I'm unfamiliar with. All my reading into examples has led me to the following code. I've truncated to the relevant section. I am having no issues with my first request to Authenticate and populate my $auth_key value with a previous request.

    #!/usr/bin/perl -w use strict; use IO::Socket::SSL qw(); use LWP::UserAgent; my $url_fw_upload=' +xxxxxxxxxxxxx'; my $ua=LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0, }); $response=$ua->post($url_fw_upload, Authorization=>"Bearer $auth_key", Content_Type=>'form-data', Content => [ "file" =>['firmware.img' => '/home/user/firmware.img'], ], );

    So the thing which is new to me is "fwLoad?X-Progress-ID", which is a Javascript generated UUID for file upload progress. I've used the same UUID that I grabbed from a browser debug session, within that browser debug I also have after the Request headers and before the Request Payload "Query String Parameters" with "X-Progress-ID: xxxxxxxxxxxxx". Since I have no Javascript capability here I'm trying to get around this and not sure if I even can without full Javascript functionality.

    The results are always the same, 400 bad request. Any suggestions to point me in the right direction would be welcome as I've come up blank in my searches so far.

Akamai authentication for IMAP.
2 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 12, 2021 at 13:36

    Hi Monks,

    How Akamai authentication can be implemented using IMAP::Client (maybe) which would authentication both IMAP creds and Akamai creds (two-factor authentication),so that mails would be processed as expected.
    Currently we have $imap->user and $imap->password methods used to authenticate user, how to add additional layer of authentication ?

    Any help regarding this would be appreciated.
    Thank you.

Add your question
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-10-15 21:47 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (69 votes). Check out past polls.