Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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
Abstract image registration or feature detection
4 direct replies — Read more / Contribute
by kikuchiyo
on Jul 01, 2022 at 10:55

    I have a task that can be best summarized by the keywords in the title, and I wonder if there is a somewhat ready-made solution, preferably in Perl, that I've overlooked.

    I have a set of points in a plane (originally coordinates of known features in an image), in two versions: one from a reference version of the image, the other from a distorted and warped version of the same image. The points themselves belong to two subsets: for the first subset, let's call them "known" points, I know the coordinates from both images, and for the second subset, "target" points, I know their coordinates only from the reference image. What I want is to determine the coordinates of these "target" points, based on the transformation determined by the corresponding "known" points.

    Maybe I'm not looking right, but I haven't found anything besides Imagemagick, dodgy Matlab recipes and a bunch of research articles.

Testing of exception during import
4 direct replies — Read more / Contribute
by Dirk80
on Jul 01, 2022 at 10:09

    Let's assume I have a module which needs 3 import parameters.

    package My::Test; use strict; use warnings; use Carp; sub import { my $class = shift; croak "Number of import parameters is wrong, stopped " unless @_ = += 3; # ... } 1;

    The good case I can check with use_ok. But the bad cases are my problem, e.g. use this class with less than 3 parameters.

    use My::Test "Param1", "Param2"; # dies because it are 2 params and no +t 3 as expected

    I want to test that this exception was thrown and I also want to check its error message for correctness. Usually I use throws_ok for this. But in this case it doesn't work because the use command is at compile time. I have no idea how to test for this exception.

    Thanks for your help!

DBI mysql router mysqlrouter cluster
1 direct reply — Read more / Contribute
by RedJeep
on Jun 30, 2022 at 15:07
    Hello friends, I am exploring using MySQL cluster with MySQL router with Perl 5. I have not been able to find any information on how to modify my database interface in Perl to connect to a cluster. Have any of you done this? My objective is for both fail over and scaling. Here is my existing code for how I connect to MySQL. Currently, this is just a single instance of MySQL.
    use DBI; use strict; use warnings; my $driver= "mysql"; my $dsn = "DBI:$driver:database=$database;host=$host"; my $dbh = DBI->connect($dsn, $user, $pw); $dbh->do('INSERT INTO test_table (fname, lname, email, comment) VALUES + (?, ?, ?, ?)', undef, $fname, $lname, $email, $comment);
    The above works fine. My hope is that MySQL clustering magically lets me use DBI and everything just like above. However, in the literature it seems that I would point my application to a MySQL router (mysqlrouter) instead of directly to the MySQL database. If I should be taking an entirely different direction to clustering for fail over and scaling feel free to let me know. The only requirements for the project are that we stick with Perl 5 and MySQL. Thank you in advance!
Pattern matching in perl
3 direct replies — Read more / Contribute
by noviceuser
on Jun 30, 2022 at 11:12

    i am writing a code where i have to find version associated with the name from a file. i am trying below code but the pattern match is not working. the file /home/test.txt contains multiple entries like below:

    Anls/01.00/windows abc/02.00/windows core/03.00/windows route/04.00/windows . . .
    my $file = "/home/test.txt"; if (-e $file) { my @list = ("Anls", "core", "route"); open(FH, '<', $file) or die $!; foreach my $x (@list) { while(<FH>){ my $pattern; if (defined($pattern) && ($pattern =~ /$x\/(.*)\/(.* +)/)) { my $version = $1; print "$x: $version\n"; } } } close(FH); }
Send before headers - in perl,
3 direct replies — Read more / Contribute
by bizactuator
on Jun 30, 2022 at 01:32
    I programmed a site in Perl back in 2007, from then until about 2012. I wrote well over 100k lines, maybe 250k lines in over 100 files.

    I cannot remember how I did it, but I remember something about it, isn't there a way to have something execute before the headers?

    Like if we already printed the headers but then need to do something to do before them, I remember I used to have to do that somehow, but I for the life of me cannot find it in my programming, or on here, but I'm pretty sure someone on here helped me with it back then.

    I may not be describing it right, but I think it was for window redirects, when we already had printed header files.
    but I cannot recall for sure.

    Do you know what I'm trying to say? or what I'm talking about?

    Sorry, I got sleep apnea so severe I almost died and it ruined my brain, I cannot recall a lot of things in whole sentences.

    I would appreciate anyone who can understand what I'm trying to say.

    Thank you,
Must have CLI of Perl's sed's n command
3 direct replies — Read more / Contribute
by abdan
on Jun 29, 2022 at 21:38

    How do we have CLI of Perl's sed's n command ?
    e.g. illustration:

    cat script.txt| perl -nle 'if (/^===\w+\s*$/){ next # ??? how to ignor +e first $_, here eg. ===Hello, to directly become replaced by next li +ne ; # ... } print'
This should be simple
3 direct replies — Read more / Contribute
by steppnav
on Jun 29, 2022 at 19:24

    Very recent perl on Cygwin

    Summary of my perl5 (revision 5 version 32 subversion 1) configuration +: Platform: osname=cygwin osvers=3.2.0(0.34053) archname=x86_64-cygwin-threads-multi uname='cygwin_nt-10.0 cygwinpro 3.2.0(0.34053) 2021-03-29 08:42 x8 +6_64 cygwin '

    Why doesn't this give just the ip address without a trailing ')'??

    #!/usr/bin/perl my $ip = "csteppfw pts/0 2022-06-27 15:53 ("; $ip =~ s/.*?(\d+\.\d+\.\d+\.\d+).*?/\1/; ## $line =~ s/.*$ip//; print "$ip\n"; -------------------- $ bin/test
fetchrow_array retruns an empty array
3 direct replies — Read more / Contribute
by eimaan
on Jun 28, 2022 at 18:29

    Hey Im coding a perl script which needs to get data from a database. But when I get a return value its comes back in an array so i dereference it. Yet it still prints out nothing. I ran the command in sqlplus and it worked there without issue. Im not sure how to solve this

    my $sth = $dbh->prepare("select XMLRECORD from F_COMPANY") or die "Couldnt prepare statement: " . $dbh->errstr; $sth->execute(); # loop through the returned data while( my ($row) = $sth->fetchrow_array()){ print "@$row\n"; }
    OUTPUT (literally nothing):
Combinations with constraints
4 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 28, 2022 at 13:13

    Hi Monks, I am trying to write a function that takes a string argument $str of the form shown below (letter + weight) and need to generate all combinations with certain restrictions; for example, no repeating numbers. I also need a perlish way to move the letter $firstLetter with the largest weight into first position. The order of the other substrings do not matter. As a secondary restriction, I also want to ensure that the combination contains the substring $substring. So, for this particular $str example, [ c?6, b?2, a%3, a?1] is a valid combination.

    Thank you very much for your help

    use strict; use Math::Combinatorics; my $firstLetter="c"; my $str="a?1,a?2,a%3,b?2,b?3,b%5,c%4,c%5,c?6,d%2"; my $substring = "a?,b%,c?"; my @combos = Math::Combinatorics::combine(4,split ",",$str); foreach my $combo (@combos) { ## check if numbers are all unique my $hash = {}; my ($count) = grep { ++$hash->{$_} > 1 } map { (split '')[2] } @$c +ombo; next if defined $count; ## place $firstLetter with largest weight in first position ## ensure that substring strings are contained within the combinat +ion }
PDF::API2: Difference between the contents of the outputs of the “to_string” and “save” methods
2 direct replies — Read more / Contribute
by espero
on Jun 28, 2022 at 08:36

    I’m developing an API application. In the API response I get a pdf in a string. If I use the “from_string” and then the “save” method of the PDF::API2 module the pdf works fine. If I write the API response string into a file (without using PDF::API2) or use the “from_string” and then the “to_string” method of the PDF::API2 module (which should be the same as I understand) I get an error message and a blank document (or blank with part of the header) when I try to open the file with a pdf reader.

    I was wondering what is the difference between the contents of the outputs of the “to_string” and “save” methods?

    Thanks in advance for your help.

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 chilling in the Monastery: (1)
As of 2022-07-02 10:26 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (102 votes). Check out past polls.