Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Seekers of Perl Wisdom

( [id://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
Using Perl's open() to investigate bash login environment
1 direct reply — Read more / Contribute
by Intrepid
on Jul 16, 2025 at 13:41

    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__
    Results on CygPerl, Bash 5.2.21
    $ perl Bash-functions.pl Results from 3716: declare -f SBP declare -f exp declare -f gawklibpath_append declare -f gawklibpath_default declare -f gawklibpath_prepend declare -f gawkpath_append declare -f gawkpath_default declare -f gawkpath_prepend declare -f profile_d
    Results on Gnu/Linux, Bash 5.2.15
    $ 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)

Parser XLSX without Crypt
1 direct reply — Read more / Contribute
by spiral
on Jul 15, 2025 at 10:04
    Because of group policy I cannot install anything that needs a dll. I need to parse an xlsx file, but

    use Spreadsheet::ParseXLSX;

    results in

    Can't locate Crypt/Mode/CBC.pm in @INC (you may need to install the Crypt::Mode::CBC module)

    Is there a way to do without this module and still be able to parse the xlsx file?
parse json
5 direct replies — Read more / Contribute
by joyfedl
on Jul 12, 2025 at 10:58

    I have a problem parsing some json message

    Here is the response I get from the request, I outputted few because the file is large

    { "get": "fixtures", "parameters": { "live": "all" }, "errors": [], "results": 43, "paging": { "current": 1, "total": 1 }, "response": [ { "fixture": { "id": 1328845, "referee": null, "timezone": "UTC", "date": "2025-07-12T12:30:00+00:00", "timestamp": 1752323400, "periods": { "first": 1752323400, "second": null }, "venue": { "id": 21763, "name": "Skreia ipl kunstgress", "city": "Skreia" }, "status": { "long": "First Half", "short": "1H", "elapsed": 25, "extra": null } }, "league": { "id": 774, "name": "3. Division - Girone 1", "country": "Norway", "logo": "https://media.api-sports.io/football/leagues/774.png" +, "flag": "https://media.api-sports.io/flags/no.svg", "season": 2025, "round": "Group 1 - 14", "standings": true }, "teams": { "home": { "id": 23420, "name": "Sortland", "logo": "https://media.api-sports.io/football/teams/23420.pn +g", "winner": null }, "away": { "id": 6974, "name": "Bćrum", "logo": "https://media.api-sports.io/football/teams/6974.png +", "winner": null } }, "goals": { "home": 0, "away": 0 }, "score": { "halftime": { "home": 0, "away": 0 }, "fulltime": { "home": null, "away": null }, "extratime": { "home": null, "away": null }, "penalty": { "home": null, "away": null } }, "events": [] }, { "fixture": { "id": 1394987, "referee": null, "timezone": "UTC", "date": "2025-07-12T12:00:00+00:00", "timestamp": 1752321600, "periods": { "first": 1752321600, "second": null }, "venue": { "id": 21680, "name": "Estádio Deputado Galdino Leite", "city": "Salvador, Bahia" }, "status": { "long": "Halftime", "short": "HT", "elapsed": 45, "extra": null } }, "league": { "id": 1073, "name": "Baiano U20", "country": "Brazil", "logo": "https://media.api-sports.io/football/leagues/1073.png +", "flag": "https://media.api-sports.io/flags/br.svg", "season": 2025, "round": "Round of 16", "standings": false }, "teams": { "home": { "id": 25814, "name": "Galícia U20", "logo": "https://media.api-sports.io/football/teams/25814.pn +g", "winner": false }, "away": { "id": 13017, "name": "Jacuipense U20", "logo": "https://media.api-sports.io/football/teams/13017.pn +g", "winner": true } }, "goals": { "home": 1, "away": 2 }, "score": { "halftime": { "home": 1, "away": 2 }, "fulltime": { "home": null, "away": null }, "extratime": { "home": null, "away": null }, "penalty": { "home": null, "away": null } }, "events": [] } ] }

    I removed use strict; because i was getting this error

    Bareword "name" not allowed while "strict subs" in use at rss.pl line +26. Bareword "name" not allowed while "strict subs" in use at rss.pl line +27.

    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; }
Web scrapping
5 direct replies — Read more / Contribute
by joyfedl
on Jul 10, 2025 at 12:57

    I have a problem with my script. i cant output the response very well

    this is the error i get

    away_teamsARRAY(0x55fbf77894a0)timesARRAY(0x55fbf743be78)home_teamsARRAY(0x55fbf71ab7b0)scoresARRAY(0x55fbf71aba98)

    this is the output i expect

    times home_teams scores away_teams 12.05. 17:00 Brighton 1 - 4 Manchester City

    Full code

    #!/usr/bin/perl - wT use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use HTML::TreeBuilder; use Data::Dumper; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); # show errors in +browser print "Content-type: text/html\n\n"; # print output to browser my $url = 'https://www.flashscore.com/football/england/premier-league- +2018-2019/results/'; my $ua = LWP::UserAgent->new; sub get_scores { my $response = $ua->get($url); if ($response->is_success) { my $tree = HTML::TreeBuilder->new; $tree->parse($response->decoded_content); return $tree; } else { die $response->status_line; } } my $results = get_scores(); my @times = map { $_->as_text } $results->look_down(_tag => 'div', cla +ss => 'event__time'); my @home_teams = map { $_->as_text } $results->look_down(_tag => 'div' +, class => 'event__participant event__participant--home'); my @scores = map { $_->as_text } $results->look_down(_tag => 'div', cl +ass => 'event__scores fontBold'); my @away_teams = map { $_->as_text } $results->look_down(_tag => 'div' +, class => 'event__participant event__participant--away'); my %dict_res; for my $ind ($results) { push @{$dict_res{'times'}}, @times[$ind]; push @{$dict_res{'home_teams'}}, @home_teams[$ind]; push @{$dict_res{'scores'}}, @scores[$ind]; push @{$dict_res{'away_teams'}}, @away_teams[$ind]; print %dict_res; }
learning about warnings
2 direct replies — Read more / Contribute
by Ivonnita
on Jul 08, 2025 at 15:58
    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!
Reading tables in MS Word
2 direct replies — Read more / Contribute
by spiral
on Jul 08, 2025 at 15:06
    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
DBD::SQLite::db commit failed: database is locked; cpan shell error
1 direct reply — Read more / Contribute
by Intrepid
on Jul 08, 2025 at 14:11

    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

    EDIT

    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?

      Soren

    Jul 08, 2025 at 18:11 UTC

File types not being picked up by script
1 direct reply — Read more / Contribute
by MShoaib
on Jul 06, 2025 at 11:33

    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.

    1: /(a directory)/4-http???wscont1.apps.microsoft.co?winstore?1.8x?2d60181a-b6d7-499a-9414-f07b0f932419?AppTile.1.396657.404061.png

    2: /(a directory)/4-https???wscont.apps.microsoft.com?winstore?6.3.0.1?100?GB?en-us?MS?467?features1de1406b-b4ec-4d86-9066-68bf9c5d67f2.json

    3: (another file path)etc.

    Can someone advise, which code to use to pick this type of files being present in 'a directory'?

    I am using following code:-

    ```
    for (@files) { $element = $_; if (-d $_) { push @directories, process_files ($_); ++$dir_counter; } elsif (-f $_) { ++$file_counter; next; } elsif ($_ =~ /\.dat$/i || $_ =~ /\.png$/i) { ++$file_counter; next; } else { print NOW "I am in else statement: process_files($_)\n"; } # else loop end
    ```
viability of new perl module
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 05, 2025 at 20:31

    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', });

    My question: Should I put this module on CPAN?

Package VERSIONs not parseable by the cpan module
1 direct reply — Read more / Contribute
by Intrepid
on Jul 05, 2025 at 13:49

    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)


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


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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?Last hourOther CB clients
    Other Users?
    Others sharing their wisdom with the Monastery: (4)
    As of 2025-07-17 00:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.