Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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
Optional Subroutine Arguments Like in <code>print FILEHANDLE LIST</code>
3 direct replies — Read more / Contribute
by mikkoi
on May 27, 2023 at 16:51

    I would like to create my own subroutines which would work the same way as print FILEHANDLE LIST works.

    Is there any non-magic way to create a subroutine with an optional first argument? Or would that just create confusion in code?

    The sub in question would be used to send a job into a queue. In most circumstances, there is only one queue. But there could be others. And the sub takes only one argument.


    queue $job; queue OTHER_QUEUE $job;
treat diff file in perl
5 direct replies — Read more / Contribute
by Anonymous Monk
on May 25, 2023 at 03:32

    Hi Esteemed Monks,

    how treat a json diff in perl?
    my @diff = <<EOF @@ -3,7 +3,7 @@; id : 6109; name: abc; value: 0; - status: ?; + status: C; time: 2023-01-01 12:00; @@ -3,8 +3,8 @@; id : 6109; name: abc; - value: 0; - status: ?; + value: 2 + status: CS; time: 2023-01-01 12:03; @@ -3,7 +3,7 @@; id : 6109; name: abc; value: 0; - status: ?; + status: C; time: 2023-01-01 12:05; EOF
    how print every change sorted by id like:
    6109 changed on 2023-01-01 12:00, before status is ? +after is C. 6109 changed on 2023-01-01 12:03, before value is 0 a +fter is 2, before status is ? after is CS. ......
    I've searched on CPAN, but all module about diff are generate or apply diff but not treat it. is there a module or convenient way to solve this? Thanks in advance.
column replacement evaluation on dataset
3 direct replies — Read more / Contribute
by Anonymous Monk
on May 24, 2023 at 10:55

    Dear Monks

    I have a dataset with columns and I want to evaluate a statement on each of the rows in the data. I can do this pretty easily. Loop

    through each column, check if the column exists in the evaluation statement. If it does, replace the column name with the value

    and do the evaluation. I can easily do this using regular expressions. Just curious how a true perl monk would approach this.

    #!/usr/bin/perl use strict; use warnings; my $row = { a => 1, b => 2, c => 3, d => 4 }; my $evalStatement="a>0"; sub evaluateRow { my ($row) = @_; ## loop through each column a,b,c,d and if column exists in the evalua +tion statement ## replace column with value if (eval(1>0)) { return 1 ## "ACCEPT row" } return 0 ## "REMOVE row" }

    Thank you !!

Set intersection problem
10 direct replies — Read more / Contribute
by baxy77bax
on May 23, 2023 at 04:05
    Dear all

    I am trying to compute the number of intersecting array elements for multiple arrays (essentially elements belonging to separate parts of venn diagrams). Initially and naively I thought this should be an easy thing to do and for 2 arrays it is:

    1. Make a hash table for one array with keys being its elements
    2. Loop through another array and count if an element exists in the previously created hash table
    3. Subtract the number of shared elements from the total number of elements of each array.

    But when the number of arrays increases the number of possible intersections between respective arrays increases (for A,B,C arrays we have A/B, A/C, B/C, A/B/C). So the problem I am having is how to scale the above algorithm.

    Does anyone know a solution to this problem even if a limited number of sets can only be included (I think this is an NP problem thus any algorithm that can produce a solution for more than 7 arrays would be acceptable)

    Thank you

Search Engine Suggestions
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 22, 2023 at 23:12

    Hi Monks, I'm looking for suggestions on a personal project. I'm writing a program to fetch a page listing items for sale on an auction site, then parse it into an array (AoA) with title, link and price for each item (this part is done). The idea is to have it search the AoA next for items I'm looking for based on search parameters I set in a config file, then build an html file listing just those items so I can view it in a browser later. I'll use a cron job to run the program nightly.

    I want to be able to do better than the basic search engine that you find on those type of sites. Maybe using something similar to SQL where you can have logical operators such as AND, OR, NOT and also be able to deal with variations in spelling of words. The search function is is where I'm looking for suggestions. Speed is not an issue and I'd like to avoid using a database. Are there any modules or examples that you can point me to? Thanks

Super newbie array question
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 22, 2023 at 17:48
    Dear Monks,
    I have recently embarked on my journey in Perl and I am already stuck with my first (most likely super trivial problem: I found a code snippet that I want to practice changing, where the example has the following array:
    @ranges = ([172,178],[183,189],[201,208]);

    and the command:
    $input =~ s/(\d+)/(grep {$1 >= $_->[0] && $1 <= $_->[1]} @ranges) ? $s +ymbol : $1/eg;

    So, my problem is, how can I create the @ranges array in the way it's written in this example? I've been trying several ways, like:
    @ranges = (); push @ranges, "[172,178]"; push @ranges, "[183,189]"; push @ranges, "[201,208]";

    but the code does not run (it runs properly using the above snippet, but somehow the array must be written in the form I have specified above, else the grep command does not work. Can you help me please?
How to find Perl demo programs?
6 direct replies — Read more / Contribute
by harangzsolt33
on May 20, 2023 at 21:59
CPAN broken after update
5 direct replies — Read more / Contribute
by misterperl
on May 19, 2023 at 11:30
    CPAN said I had an update this morning, so I performed it, to v2.36 . I THINK the previous version was around 1.96. I'm not sure because on the older systems, the command
    linux> cpan -v linux>
    does just that (nothing, no error, but no version either). On the updated system it reports v.2.36

    Since the update, when I try to do almost anything, I get this message:

    CPAN: Net::SSLeay loaded ok (v1.55) CPAN: IO::Socket::SSL loaded ok (v2.056) Fetching with HTTP::Tiny: HTTP::Tiny failed with an internal error: SSL connection failed for cp SSL connect attempt failed error:14090086:SSL routines:ssl3_g +et_server_certificate:certificate verify failed
    I talked to CHATBOT AI, who suggested I edit ~/.cpan/CPAN/ and change 'urllist' => [q] </code>to'urllist' => [q[]] (remove the "s") which I did; no effect.

    I also tried to change it to both of these:

    'urllist' => [q[]] and 'urllist' => [q[]]
    But the error remained. It STILL looked in, no matter WHAT I set that line to.

    I also deleted /.cpan/BUILD , which chatbotAI said would kill the cache. No change, still the same error. It's ignoring the config changes. Yet when I rm -f .cpan, it rebuilds it THERE. So it does expect the config to be there. I'm doing all of this as root. I also did an updatebb and then locate on .cpan and the only one on the box is under ~/. Surprisingly, even

    cpan -M Crypt::RSA
    results in the same error and STILL looks in!
    Fetching with HTTP::Tiny:

    Friday, I have a ton of code to write, and down this rabbit-hole was the LAST thing I needed! Help is most appreciated- even help on going BACK to v1.9x ?

Win32::PowerPoint extension
1 direct reply — Read more / Contribute
by EnzoXenon
on May 19, 2023 at 10:52
    I'm attempting to extend the Win32::PowerPoint module to alter the size of a page in PowerPoint.

    In the module I've added the following to define the page names to the enumeration from the Microsoft documentation

    ppSlideSize35MM => 4, ppSlideSizeA3Paper => 9, ppSlideSizeA4Paper => 3, ppSlideSizeB4ISOPaper => 10, ppSlideSizeB4JISPaper => 12, ppSlideSizeB5ISOPaper => 11, ppSlideSizeB5JISPaper => 13, ppSlideSizeBanner => 6, ppSlideSizeCustom => 7, ppSlideSizeHagakiCard => 14, ppSlideSizeLedgerPaper => 8, ppSlideSizeLetterPaper => 2, ppSlideSizeOnScreen => 1, ppSlideSizeOverhead => 5,

    In the module I've added a method to alter the page setup like this

    sub page_setup { my ($self, $options) = @_; $options = {} unless ref $options eq 'HASH'; $self->presentation->PageSetup->SlideSize($options->{slidesize}); $self->presentation->PageSetup->SlideWidth($options->{width}); $self->presentation->PageSetup->SlideHeight($options->{height}); }

    In my call to this function I try to set the slide size with no luck

    # Set the slide size $PPT->page_setup( { slidesize => 'ppSlideSizeLetterPaper', width => 11*72, height => 8.5*72 } );

    When I debug the code and print out the slide information ... from within from this code

    print "\ slide size=" . $self->presentation->PageSetu +p->SlideSize . "\n"; print " width=" . $self->presentation->PageSetup->Sl +ideWidth . "\n"; print " height=" . $self->presentation->PageSetup->Sl +ideHeight . "\n\n";

    I list out the options called (they seem to be right) and get the answers like this options: slidesize=ppSlideSizeLetterPaper height=612 width=792 slide size=7 width=960 height=540
    So, I can properly read the current values but I can't set new ones. Any wisdom would be greatly apprecaited.

    Your humble apprentice formerly registered as nzsvz9 but can't find or fix his login so newly creating this EnzoXenon account

Perl module to "humanise" dates and times
5 direct replies — Read more / Contribute
by Galdor
on May 19, 2023 at 06:43
    Anyone know a library to render DateTime objects into "yesterday", "last week", "three months ago"... etc? Thanks!

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 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 about the Monastery: (2)
As of 2023-05-28 08:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found