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.
After a lot of tweaking and experimentation I got code that will display for me the functions that are defined in a bash shell on my system. I first wrote the code 13 years ago. I broke this code out of a much larger modulino that I started back then and never got entirely working.
This scriptlet is working in CygPerl but not in Perl on Linux.
#!/usr/bin/env perl
# Last modified: Wed Jul 16 2025 12:52:52 PM -04:00 [EDT]
# Bash-functions.pl
use strict;
use v5.18;
use utf8;
use warnings;
local $ENV{'PERL5SHELL'} = q=/usr/bin/bash=;
local $ENV{'SHELL'} = q=/usr/bin/bash=;
my $spawnFH;
my $elist;
my $cPid = open( $spawnFH, q[-|], qq[$ENV{'PERL5SHELL'} -login command
+ builtin declare -p -F] )
or die "Bad open from pipe: $!";
if ( $cPid ) {
$elist = join qq[], grep {/^declare -f/} <$spawnFH>;
close $spawnFH or warn qq/Bad close on process $cPid: $!|$?/;
}
print qq[Results from $cPid:\n], $elist, qq[\n];
__END__
$ perl Bash-functions.pl
/usr/bin/bash: command: No such file or directory
Bad close on process 12284: |32512 at Downloads/Bash-functions.pl line
+ 17.
Results from 12284:
Apparently bash behaves differently, when invoked this way on Linux. If I use the bash invocation alone (on Linux): command builtin declare -p -F, I see a nice list of functions. Also, I am puzzled wrt why I need to start the command with $PERL5SHELL. I would have thought, based on documentation I read, that seeing shell metacharacters in the open string would have caused perl to automatically invoke a shell.
Jul 16, 2025 at 17:46 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young Donald Fagen —> I.G.Y. (Slightly modified for inclusiveness)
When i try to run my code this is the error i get Not an ARRAY reference at script.pl line 18.
my full script is
#!/usr/bin/perl
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
my $url = "https://v3.football.api-sports.io/fixtures?live=all";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $url);
$req->header('x-rapidapi-host' => 'v3.football.api-sports.io');
$req->header('x-rapidapi-key' => '.......');
my $response = $ua->request($req);
my $parse_json = JSON::XS->new->decode ($response->content);
my @matches = $parse_json->[1]; # Get all results in "response": [ ]
if ($response->is_success) {
foreach my $results (@matches) {
my $matche_status = $results->{status}->{short};
my $teamA = $results->{teams}->{home}>{name};
my $teamB = $results->{teams}->{away}>{name};
my $teamA_scores_HT = $results->{score}->{halftime}->{home};
my $teamB_scores_HT = $results->{score}->{halftime}->{away};
my $teamA_scores_FT = $results->{score}->{fulltime}->{home};
my $teamB_scores_FT = $results->{score}->{fulltime}->{away};
print "$matche_status | $teamA has scored $teamA_scores_HT in
+Halftime | $teamA_scores_FT in fulltime"; # Get all Home teams result
+s
print "$matche_status | $teamB has scored $teamB_scores_HT in
+Halftime | $teamB_scores_FT in fulltime"; # Get all Away teams result
+s
# Print Such
# HT | Arsenal has scored 1 in halftime | 2 in fulltime
# FT | Chelsea has scored 2 in halftime | 3 in fulltime
}
} else {
print $response->status_line;
}
I am getting the following warning for a perl script to generate a volume: 1234surface 6900 surface WARNING:Your grid dimensions are mutually prime. Convergence is very unlikely. I understand this is not an error, but what does it mean? How much this warning can affect the accuracy or reliability of my results?
Thank you!
I need to automate some tasks and this involves reading some MS Word files.
I recently came across MsOffice::Word::Surgeon.
Specifically what I want to do is read a word file, recognize tables in it and read tables, where specific columns may have relevant information, such as a key. Does anyone have or can give an example of this?
E.g.
use MsOffice::Word::Surgeon;
my $surgeon = MsOffice::Word::Surgeon->new(docx => $file);
my $main_text = $surgeon->document->plain_text;
# if I serialize this way, I lose table info
When I installed CPAN::SQLite and set cpan opt use_sqlite to true, the next time I started cpan shell I got this error:
2025-07-08 12:40:23 (3.53 MB/s) - ‘/home/somian/.cpan/sources/modules/
+03modlist.data.gz.tmp11438’ saved [248/248]
Database was generated on Mon, 07 Jul 2025 15:41:26 GMT
Updating database file ... DBD::SQLite::db commit failed: database is
+locked at /usr/local/lib/perl5/site_perl/CPAN/SQLite/Populate.pm line
+ 663, <DATA> line 268361.
DBD::SQLite::db commit failed: database is locked at /usr/local/lib/pe
+rl5/site_perl/CPAN/SQLite/Populate.pm line 663, <DATA> line 268361.
Catching error: "system /usr/local/bin/perl -MCPAN::SQLite::META=setup
+,update,check -e update failed: 2816 at /usr/local/lib/perl5/site_per
+l/CPAN/SQLite/META.pm line 318.\cJ" at /usr/local/lib/perl5/5.40.1/CP
+AN.pm line 397.
CPAN::shell() called at -e line 1
Oh, s**t. I had an earlier instance of CPAN's shell running in the background in a terminal. I'm writing this update very quickly so I can say NEVER MIND, before anyone decides to waste their time telling me what's wrong. ;-).
This is on Gnu/Linux, perl 5.40.1, CPAN.pm version 2.36. The error is repeatable; if I set use_sqlite via o conf, I will get the error.
I understand what a locked database is, although I haven't had to learn the
specifics of database management (I've long been an "enthusiast" - self-taught -
rather than a "professional" who would be required to know databases for w$rk). My
questions are: has anyone else seen this error with CPAN?
And, What's the magnitude of the performance penalty for not
using SQLite with CPAN?
Hi,
I am trying to pick files and directories from multiple directories and folders for further processing in my programme logic.
I am able to pick majority of the files and directories. However, with -f and all other remaining file operators (that I have already tried so far), I am unable to pick following type of files from the cache folder.
I frequently use Python's matplotlib to make figures. I've made my own perl module for making quick plots in perl using matplotlib. I've found matplotlib to make figures inconsistently, and requires a lot more time for me to switch between the languages. So my perl scripts make a python temp file, and execute it. It's not super-efficient, I know, but it saves me time in both writing scripts and reading documentation.
Plotting a hash is very easy:
use Matplotlib::Simple 'plot';
plot({
'output.filename' => 'svg/single.barplot.svg',
data => { # simple hash
Fri => 76, Mon => 73, Sat => 26, Sun => 11, Thu => 94, T
+ue => 93, Wed => 77
},
'plot.type' => 'bar',
xlabel => '# of Days',
ylabel => 'Count (Applications)',
title => 'Rejections by Days',
});
I don't see a better place than SoPW at the Monastery to put this so I'll
just dump it here and see what happens.
Just a simple inquiry: I just ran cpan (not cpanplus, which I post about a lot); I
entered the command r for "reporting outdated/upgradeable modules" and cpan
reported 92 unparseable module versions. Whoa. That makes me want to ask: is
it really that difficult to write a package with a sane / parseable version? Or is
cpan's programmatic notions of "parseable" odd or too strict? Opinions and
knowledge welcomed.
Soren
Jul 05, 2025 at 17:47 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young Donald Fagen —> I.G.Y. (Slightly modified for inclusiveness)