Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

The Monastery Gates

( [id://131] : superdoc . print w/replies, xml ) Need Help??

If you're new here please read PerlMonks FAQ
and Create a new user.

Quests
poll ideas quest 2024
Starts at: Jan 01, 2024 at 00:00
Ends at: Dec 31, 2024 at 23:59
Current Status: Active
0 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
February 08, 2024 @ 6pm CT ~ Houston Perl Mongers Zoom Meeting
on Jan 29, 2024 at 19:11
2 replies by oodler
    February 08, 6pm CT ~ Houston Perl Mongers Zoom Meeting 🔗 Thu Jan 25 2024
    Title: Using Perl Prototypes

    When: Thur February 8th at 6:00-8:00 PM CT (+6 UTC)

    Where: (virtual, see below):

    https://us02web.zoom.us/j/920069702
    Meeting ID: 920 069 702
    Password can be found by running this statement.
    perl -e 'print +(0b1000100).((3<<2)*10).(010)."\n"' # 681208
    Original post:
    https://houstonperlmongers.org/posts/3a99ac5b-f9f9-4409-a38c-e9ef91d972c8
Serious vulnerability in Spreadsheet::ParseExcel (SOLVED)
on Jan 03, 2024 at 14:51
1 reply by Cody Fendant

    A serious vulnerability in Spreadsheet::ParseExcel has been announced.

    “This library is used by the Amavis virus scanner that runs on Barracuda ESG appliances. An attacker can trigger the vulnerability to execute arbitrary code on vulnerable ESG appliances through parameter injection.”

    No mention of specific version numbers or of response from the Perl community in any way. What would we expect to happen in a situation like this?

Supplications
How To Remove Warnings From Regex
1 direct reply — Read more / Contribute
by roho
on Feb 03, 2024 at 22:39
    I need to find two consecutive occurrences of a given character. The following SSCCE works ('cc' matches, 'cz' does not match), but I have to turn off 'uninitialized' warnings prior to the regex to make it work without getting 'uninitialized' warning messages about $1. Do you know a better way to do this, preferrably without the need to suppress warnings?

    On a side note, the "start of string" anchor (^) in the regex is fine, but if I add an "end of string" anchor to the regex (either '$' or '\z') the match fails. The match should not fail with the addition of an "end of string" anchor, because each string is exactly 2 characters long.

    Where is Jeffrey Friedl when you need him? (ha ha) :-)

    #!/usr/bin/perl use strict; use warnings; my @txt = ('cc','cz'); for (@txt) { no warnings 'uninitialized'; if (m/^(.)$1/) { print "True \$_ = |$_| \$1 = |$1|\n"; } else { print "False \$_ = |$_| \$1 = |$1|\n"; } use warnings; }

    "It's not how hard you work, it's how much you get done."

How to implement a Queue that doesn't leak memory?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 03, 2024 at 06:00
    There are many posts showing how to implement a queue (FIFO) using push and shift, and there's a lot of CPAN modules also using this method, as well as most of the Perl books. But they don't address, or even mention, the issue of memory leakage as described in Shift, Pop, Unshift and Push with Impunity!:
    One consequence of perl's list implementation is that queues implemented using perl lists end up "creeping forward" through the preallocated array space leading to reallocations even though the queue itself may never contain many elements.
    What is the proper (and perlish) way to implement a queue that won't leak memory? And is there already a CPAN module that implements it?
Tk::Tree how to set color of entry after tree creation
1 direct reply — Read more / Contribute
by EnzoXenon
on Feb 01, 2024 at 14:26
    Hello Monks,

    I searched here for Tk::Tree and did not find a relevant article, CPAN, and O'Reilly ... but the answer is elusive.

    I am able to populate a Tk::Tree with a structure, and after some processing, I would like to change the color of an entry is the tree - but I can't get the call and syntax right.

    Here's the sample Tk::Tree code:

    use Tk; use Tk::Tree; my $mw = MainWindow->new(-title => 'Tree'); my $tree = $mw->Tree->pack(-fill => 'both', -expand => 1); foreach (qw/orange orange.red orange.yellow green green.blue green.yel +low purple purple.red purple.blue/) { $tree->add($_, -text => $_); } # Different things to try here $tree->autosetmode(); MainLoop;
    1. Try itemConfigure:
    $tree->itemConfigure('orange.red', 0, -foreground => 'blue');
    Error:
    Bad option `-foreground' at C:/Strawberry/perl/site/lib/Tk.pm line 251 +.
    2. Try itemConfigure with a '1' since altering orage.red would be in column 1 of a HList:
    $tree->itemConfigure('orange.red', 1, -foreground => 'blue');
    Error:
    Column "1" does not exist at C:/Strawberry/perl/site/lib/Tk.pm line 25 +1.
    3. OK. Try option -fill instead of -foreground because of other observed inconsistencies in Tk:
    $tree->itemConfigure('orange.red', 0, -fill => 'blue');
    Error:
    Bad option `-fill' at C:/Strawberry/perl/site/lib/Tk.pm line 251.

    I've tried configure, itemConfigure, entryConfigure (that's for menus) and I'm just not getting it right.

    Please help!

When to use eval
3 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 01, 2024 at 11:27
    What does eval catch? A function that issues a die? A function that just returns an error?
    for instance when using LWP.do you wrap the response object with eval? Does it die on a timeout which you can catch?
    Should you always wrap in eval functions imported from modules?
    Or builtins.For instance ,open , returns undef when failing but it doesn't kill the rest of the program due to the 'exception'.
    Should you wrap it in eval and will eval catch the undef return or it would catch it in case open would also fire a 'die'?
Is require still required?
4 direct replies — Read more / Contribute
by Bod
on Jan 31, 2024 at 17:48

    I've been looking at a question I asked 3 years ago in Refactoring webcode to use templates

    How things have changed since then. We've closed down the part of the business that I refactored all the code for, but I certainly learnt a lot in the process.

    One of the things I refactored and now do as standard is to have pretty much all common code in modules. Although they were common in my code until a few years back, I now never use the require keyword. This got me thinking...is require ever still required or is it obsolete in the modern world?

Persistent data
2 direct replies — Read more / Contribute
by Bod
on Jan 31, 2024 at 17:37

    I'm writing an XML Sitemap generator based around WWW::Crawl

    I want to record the priority to set each entry in the sitemap. My first thought was to use a CSV or similar text file but it could become huge and cumbersome. So what are the alternatives?

    I could write this server-side where I have a MariaDB instance running so storage is no problem. But I'm thinking I want to run it client side although I don't really know why. So my choice seems to be to hold the data in a Storable object. Run MariaDB, MySQL or similar locally or use DBD::SQLite from within Perl. No doubt there are other choices...

    Which would you do and why?

    What would you definitely avoid doing and why?

Why Is Writing to a Binary File so Hard?[SOLVED]
2 direct replies — Read more / Contribute
by jmlynesjr
on Jan 31, 2024 at 15:36

    SOLVED: Trial and error with pack options.

    my $c = pack('W*', @binbytes); print $out $c;

    Been away for awhile...

    Background: I recently discovered the Simh/Open-Simh open source project. This project provides a framework for building simulators for vintage computers(many minis are currently supported - DG, DEC, HP, Honeywell, XDS, etc.). As a Data General(DG) Nova/Eclipse programmer from the 70s, I decided to download the Nova simulator and give it a try. It's a very slick piece of software. It runs the original Data General binary software distributions at about 40x speed on my Dell laptop. I compiled and ran a FORTRAN IV code from the 70s. The simulator represents peripheral devices as unstructured linux files(Ubuntu 22.04 LTS in my case). I want to be able to move text files from the DG RDOS filesystem to/from the linux file system mostly to have access to an editor that I remember how to use.

    I'm trying to do this via the DG papertape reader and papertape punch devices. Going from RDOS to linux was easy. Going from linux back to RDOS not so easy. HELP! I can't get the script to write out the binary file. It needs to be actual binary data not a text representation of binary data

    The fix has to be simple. I just don't see it.

    Notes: RDOS - Data General's Realtime Disk Operating System

    RDOS -> linux convert CRs to LFs

    linux -> RDOS convert LFs to CRs

    Original RDOS Macro file output by the RDOS BPUNCH(binary punch) command.

    Output to a simulated papertape punch. The papertape punch is simulated as an unstructured linux file.

    MESSAGE INIT WORKING DIRECTORIES-SETUP.MC MESSAGE INIT MACROS INIT UTIL INIT FORT DIR PETE GDIR

    Hexdump of the above macro file as a linux binary file, one byte for each character punched. Note the CR(0d) RDOS line endings.

    00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |......... +.......| * 00000190 4d 45 53 53 41 47 45 20 49 4e 49 54 20 57 4f 52 |MESSAGE I +NIT WOR| 000001a0 4b 49 4e 47 20 44 49 52 45 43 54 4f 52 49 45 53 |KING DIRE +CTORIES| 000001b0 2d 53 45 54 55 50 2e 4d 43 0d 4d 45 53 53 41 47 |-SETUP.MC +.MESSAG| 000001c0 45 0d 49 4e 49 54 20 4d 41 43 52 4f 53 0d 49 4e |E.INIT MA +CROS.IN| 000001d0 49 54 20 55 54 49 4c 0d 49 4e 49 54 20 46 4f 52 |IT UTIL.I +NIT FOR| 000001e0 54 0d 44 49 52 20 50 45 54 45 0d 47 44 49 52 0d |T.DIR PET +E.GDIR.| 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |......... +.......| * 00000380

    ptreader.pl takes the above binary file, replaces the RDOS CR(od) line endings with linux LF(0a) line endings, strips off all of the nulls(00), and outputs a linux text file. Read() works fine to read the BPUNCH binary file.

    #! /usr/bin/perl # ptreader.pl - Papertape decoder for the Simh Data General Nova/Eclip +se Simulator # The linux file PTP.OUT is produced by the RDOS BPU +NCH command # PTP.OUT is a binary file that has a lot of leading + and trailing nulls # The nulls are stripped off and the remainder is co +pied to the output # file PTP.TXT. Line endings are converted. # # ptreader provides a way to copy text files from # the simulated RDOS filesystem to the linux filesys +tem # # RDOS -> PTP.OUT -> ptreader.pl -> PTP.TXT # # Created by: James M. Lynes jr. # Created on: January 29,2024 # Last Modified: 01/29/2024 - Initial version # 01/30/2024 - Additional comments, fix line ending(0x0 +A) # # Usage: On RDOS: BPUNCH filename # Creates the (binary formatted) linux file: PTP.OU +T # # On linux: ./ptreader.pl # Reads PTP.OUT and creates the reformated linux te +xt file PTP.TXT # # Note: Use ptwriter.pl to format a linux text file to be rea +d by RDOS use strict; use warnings; open(my $in, '<:raw', "PTP.OUT") or die; open(my $out, '>', "PTP.TXT") or die; my $content; my $length; my $maxlength = 4000; my @inbytes; my @outbytes; $length = read($in, $content, $maxlength); # Read the binary fil +e print "Length: $length\n"; # Show total bytes re +ad @inbytes = unpack("C*", $content); # Unpack bytes into a +n array foreach(@inbytes) { # Delete null bytes next if($_ == 0); push(@outbytes, $_); } foreach(@outbytes){printf ("0x%02X ", $_)}; # Show a hex dump of +array print "\n"; foreach(@outbytes) { # Show the text read + my $code = chr($_); if($_ == 0x0D) { $code = chr(0x0A); # Fix linux line end +ing } print "$code"; print $out $code; # Copy text to output + file } close $in; close $out;

    ptwriter is supposed to take a linux text file, change LFs back to CRs, and write out the result into a binary file. This code fails miserably! Actually getting it to write out the binary file is the problem.

    #! /usr/bin/perl # ptwriter.pl - Papertape encoder for the Simh Data General Nova/Eclip +se Simulator # The linux file PTR.IN is a binary formatted file w +hich can # be read from the RDOS $PTR1 device. # # The user is prompted for the linux text file to conver +t # # ptwriter provides a way to copy text files from # the linux filesystem to the simulated RDOS filesys +tem # # linux file -> ptwriter.pl -> PTR.IN -> RDOS # # Created by: James M. Lynes jr. # Created on: January 30,2024 # Last Modified: 01/30/2024 - Initial version # # # Usage: On linux: ./ptwriter.pl # Creates the (binary formatted) linux file: PTR.IN # User is prompted for the linux text file name # # On RDOS: XFER/A $PTR1 filename # Copies linux file PTP.IN to RDOS file filename # # # Note: Use ptreader.pl to format a RDOS binary file into a l +inux text file use strict; use warnings; print "\n\n"; print "ptwriter - convert linux text file to RDOS papertape input file +\n"; print "=============================================================== +\n"; print "Input linux text file name: "; my $lfile = <STDIN>; chomp($lfile); open(my $in, '<', $lfile) or die; open(my $out, '>', "PTR.IN") or die; my @inbytes; my @bytes; my @outbytes; my $outbytes; my @binbytes; while(my $line = <$in>) { # Read text file con +vert to binary @bytes = unpack('C*', $line); push(@outbytes, @bytes); } my $len = $#outbytes + 1; print "Characters Read: $len\n\n"; #foreach(@outbytes){printf ("0x%02X ", $_)}; # Show a hex dump o +f array #print "\n\n"; foreach(@outbytes) { my $code = $_; if($code == 0x0A) { # Convert linux line +end to RDOS line end $code = 0x0C; } # printf("0x%02X ", $code); # Show the converted + text push(@binbytes, $code); } #print "\n\n"; #foreach(@binbytes) {printf ("0x%02X ", $_)}; # *** Output data lo +oks good at this point *** #print "\n\n"; my $ctr = 0; foreach(@binbytes) { # *** This code not +producing correct my $c = $binbytes[$ctr]; # binary fil +e *** print "$c"; print $out $c; $ctr = $ctr + 1; } close $in; close $out;

    James

    There's never enough time to do it right, but always enough time to do it over...

Module Recommendations
5 direct replies — Read more / Contribute
by TStanley
on Jan 31, 2024 at 09:58

    After a six year dry spell, I once again come before my brothers and sisters to seek help :)

    I now have a project in front of me to read in a number of csv files from our system, then produce a single report of some kind, either in HTML or a csv format. I was leaning towards HTML, since I would be able to format results into a table and highlight a table cell that has a value that is not in line with our best practice specifications.

    I am looking for suggestions on what modules I should be using to make this task as painless as possible. I haven't touched the perl interpreter in all this time, so I have my trusty Camel book right next to me to look up anything I have forgotten. And as always, thank you for any pointers in the right direction.


    TStanley
    --------
    The only thing necessary for evil to flourish is for good men to do nothing -- Edmund Burke
Raku classes: syntax question
1 direct reply — Read more / Contribute
by 7stud
on Jan 30, 2024 at 21:10
    Dear Monks,

    I am trying to understand the following code, in particular the set method::

    use v6; class Point { has $.x = 0; has $.y = 0; method gist { "[$.x, $.y]" } method set( :$x = $.x, :$y = $.y ) { $!x = $x; $!y = $y; } }

    Can someone explain all of the syntax used in the set method?

    And, another question if I may: is "Learning Perl 6" outdated?

    Thanks.

DBI handle_error debugging
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jan 30, 2024 at 01:58
    I set a DBI error handler 'handle_error' with $dbh->{RaiseError} = 1; and I want to inspect the arguments passed to it under the debugger with perl -d
    sub handle_error { my $errortext = shift; my $handle = shift; my $dbh; my $dbh = $handle->{'Database'};
    when I run it under the debugger when inside 'handle_error' I get
    DB<2> x @_ 0 'Duplicate key on INSERT detected. (Tue Jan 30 08:45:55 2024)' 1 DBI::db=HASH(0x33c6af0) empty hash 2 undef
    However DBI::db=HASH(0x33c6af0) cannot be empty since I consume it in the next lines with
    my $dbh = $handle->{'Database'};

    Why does the debugger say that it is empty, and how can I inspect
    the contents of DBI::db=HASH(0x33c6af0) ?
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 having a coffee break in the Monastery: (8)
As of 2024-02-05 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found