Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
sending raw soap envelope with soap::lite
1 direct reply — Read more / Contribute
by ffrost
on Nov 29, 2023 at 12:26

    Hoping this is an easy problem to solve as my attempts are failing miserably. Using the AI bots and Google only seem to create solutions where the output is all mungled up or the XML elements get repeated, or worse new XML elements are added.

    In short, I'm creating a specific soap envelope I need to send to the endpoint web service. The reason is due to complexity and the inability for SOAP::Lite to render the output correctly. This also provides more control for changes as they occur. But when I try to make the call to the web service and send the envelope it seems to be sending the data modified, or the method call is not correct, etc.

    I'll post an example below and hopefully someone has a 'duh' answer I seem to be missing.

    use SOAP::Lite; use SOAP::Lite on_action => sub {sprintf '%s/%s',@_}; $proxy = 'https://proxy.com/2.3'; $uri = 'https://uri.dataservices.training'; $method = 'methodCall'; $soap = SOAP::Lite ->proxy($proxy) ->uri($uri); $soapenv = <<'EOF'; <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope ... (bunch of NS values)> <soap:Header> (bunch of header settings here) </soap:Header> <soap:Body> (bunch of body settings here) </soap:Body> </soap:Envelope> EOF $results = $soap->call("$uri/$method",$soapenv);

    This is resulting in the error "Element ..($uri/$method) ... can't be allowed in valid XML message.

Compare two strings of same length, character-by-character (strings)
5 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 28, 2023 at 16:51
    Hi Monks,
    I have two strings, of the same length, and I want to check how many of the characters are the same.
    Example:
    $str1='LFGSLSIIVAHHM'; $str2='LFGSLSIIVSHHM';

    I don't want to do LCSS, because it will only give me LFGSLSIIV, although we also have HHM. What I have done is to split each string and then compare the characters in each position, increase a 'correct' counter by 1 if they are the same and then compare the number of correct characters to the length of the string (to see what % of the string was the exact match).
    I was wondering if there would be any quicker solution to this, with a module or something that I might not be familiar with.
Trying to translate overflowing JS code to Perl
4 direct replies — Read more / Contribute
by bliako
on Nov 28, 2023 at 13:46

    Wise Monks,

    I am trying to translate some JS code into Perl. The problem is that I think said JS code does not handle well overflows when doing a left shift and it calculates the result (let's say a checksum) wrongly. But this is now the result and I must emulate that result in my Perl translation. I can not fix the JS code, it is not mine. Question is: how?

    Here is the gist of it assuming a 64bit Linux console with node.js installed and bash:

    node -e 'console.log(1<<30);' 1073741824 echo $((1<<30)) 1073741824 # same result perl -e 'print 1<<30, "\n"' 1073741824 # same result node -e 'console.log(1<<31);' -2147483648 # overflow in 32bit! echo $((1<<31)) 2147483648 # correct result perl -e 'print 1<<31, "\n"' 2147483648 # same result # to obtain the overflow in bash echo $((1<<63)) -9223372036854775808 # overflow in 64bit # still perl does not perl -e 'print 1<<63, "\n"' 9223372036854775808 perl -e 'print 1<<64, "\n"' 0 # gotcha! # this is when I realised the problem: node -e 'console.log(1169367104<<5);' -1234958336 echo $((1169367104<<5)) 37419747328 perl -e 'print 1169367104<<5, "\n"' 37419747328 # same result

    (note: if you don't have node.js open your browser, open its 'web developer tools', go to tab 'console' and just paste that bit of harmless js code

    So, I am asking: how can I make perl print -1234958336 when left-shifting 1169367104<<5 ?

    use Test::More; is(1169367104<<5, -1234958336, "simulated JS 32bit shift."); done_testing;

    bw, bliako

    Edit: I have asked a more general question about JS/C/Perl integer overflows at https://stackoverflow.com/questions/77584450/emulate-javascripts-32bit-signed-integer-arithmetic-to-c-or-perl-some-discr

Starman "Server closed connection without sending any data back"
2 direct replies — Read more / Contribute
by nikosv
on Nov 28, 2023 at 05:17
    I have setup a plack psgi application tha works with cgi files. When I start starman server from the shell of the user 'starman' the service runs fine and responds to requests.
    When I try to set it up as a systemd Unit (Centos) , the client gets an error of "Server closed connection without sending any data back" without emitting any data.OS is Centos7. Can't find anything in the log files,expect from dmseg which has error :
    111362894.832068 starman master 24776: segfault at c1 ip 00007f29bd8d2057 sp
     00007fff6ba44168 error 4 in XS.so7f29bd8cf000+15000
    
    The service is set up as :
    [Unit] Description=StarmanService [Service] Type=simple User=starman Group=starman ExecStart=/home/starman/perl5/bin/starman -E debug --ssl-key=/home/sta +rman/starm anpem+5-key.pem --ssl-cert=/home/starman/starmanpem+5.pem --listen :50 +00:ssl --w orkers=1 /home/starman/app.psgi --access-log /home/starman/access.log +--user=sta rman --error-log /home/starman/error1.log Restart=always WorkingDirectory=/home/starman/cgi-bin [Install] WantedBy=multi-user.target
How to create and name module tarball for CPAN
3 direct replies — Read more / Contribute
by Polyglot
on Nov 27, 2023 at 13:42
    Another simple newbie CPAN question:

    What should I name my tarball for upload to CPAN?

    I have chosen to give the package I am creating a home at Regexp::CharClasses::Thai on CPAN, so the final filename in that tree is simply "Thai.pm". However, obviously it needs to find its way past the first two levels in that tree...so I'm assuming that I should name it "Regexp-CharClasses-Thai.tar" (which contains the tarball made of the entire package and its associated files). Would this be a correct assumption? Alternatively, should it be compressed as well, i.e. "Regexp-CharClasses-Thai.tar.gz" OR "Regexp-CharClasses-Thai.tgz"?

    Also, do I create the tarball to include the directories './Regexp/CharClasses/Thai/', or just the final directory (the one with the MakeFile.PL, etc., in this case /Thai/), or something else, e.g. no prior directories at all, just the one with the package files and subdirs?

    Note that I have already checked, and found no specifics on how to name or structure the tarball (it's as if all the documentation assumes a root-level module) in any of these 'official' places:

    I hate asking so many questions, but I'm rather stumped on this one and wishing the kind folk who have worked so hard on the documentation for how to create and submit modules to CPAN would have given some thought to the creation of the tarball once the module itself was prepared. (Or perhaps one of you might direct me to where this was done and has yet escaped my notice.)

    One additional question that came up while reading the materials linked above: Can I just submit a link to CPAN and then host the module myself? If so, how would this be done?

    Blessings,

    ~Polyglot~

Can 32-bit and 64-bit modules coexist in a working installation?
2 direct replies — Read more / Contribute
by hexcoder
on Nov 27, 2023 at 09:12
    Esteemed monks,
    I am deploying an Perl/Tk application (currently using 32-bit Strawberry Perl 5.32.1.1 with a self built Tk module installed locally in directory Tk). The Perl itself is excluded and has to be installed independently.

    Now I am planning to upgrade to 64-bit Strawberry Perl 5.38.0.1, which means to compile Tk for 64-bit. The compilation was possible after applying a patch to the Tk sources (https://github.com/chrstphrchvz/perl-tk/commit/0cc1fd7c599fc6b7050fcd7442f10824b032c462.patch).

    Now, that i am prepared to integrate the new versions, I am wondering, if it might be possible to have both variants (32-bit and 64-bit) of the Tk module installed together. That would have the advantage, that the application would work with the old 32-bit Perl and also with the new 64-bit Perl. This fallback would give my clients more time to migrate to the new Perl version.

    As far as I understand it the compiled module parts reside in the directory auto/Tk (which complements the Tk directory). If I would put my 64-bit parts in new directories Tk64 and auto/Tk64, would a simple use lib 'Tk' versus use lib 'Tk64' be enough to find the corresponding binaries?

    Many thanks for your hints!
    Hexcoder

Listing dependencies for Perl modules--should even the common ones get listed?
3 direct replies — Read more / Contribute
by Polyglot
on Nov 26, 2023 at 07:05
    Silly question, perhaps, but I'm quite a beginner with making a CPAN-worthy module (yes, still working on that, between other real-life projects that hinder progress)--and searching online did not help me find an answer:

    According to the h2xs utility, the README file should contain a list of the module's dependencies. I have a hard time thinking such things as use strict; should need to be listed, but what about require Exporter;?

    If my dependencies are strictly limited to the following, which of these, if any, should be listed in the README file?

    use 5.008003; use strict; use warnings; require Exporter;

    I would think these are all virtually taken for granted, and ubiquitous on ordinary installations of Perl. Do I still list them? If not, do I report "No dependencies"? (That doesn't seem quite accurate, either.) What is considered the best practice here?

    Blessings,

    ~Polyglot~

using smartmatch for range matching
4 direct replies — Read more / Contribute
by perltux
on Nov 25, 2023 at 11:03
    I use smartmatch for checking whether an integer number is within a certain range, like this:

    if ( $number~~[1416..1494] ) { do whatever }

    But since i upgraded to a recent Perl version i'm getting a "Smartmatch is deprecated" warning.

    Why would such a useful operator be depreciated?

    Do I really have to replace '~~' with:

    if ( $number>=1416 and $number<=1494 ) { do whatever }

    Is there a more elegant solution similar to the smartmatch example?

    Also is this depreciation of smartmatch definitive or is there a chance that the Perl devs will change their mind and keep it?
    Perl is great because of these brilliant operators, removing them removes a bit of the uniqueness of Perl.

Download full perl documentation?
5 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 24, 2023 at 22:36
    Is it any longer possible to download full perl documentation,
    that I can read while I'm off-line?
    
    I can now read on-line e.g. https://perldoc.perl.org/perlvar .
    I'm glad that the information is still available.
    
    I used to be able to see essentially this page by typing,
    at the bash prompt, something like 'man perlvar'.  I'd like to
    be able to do this now, when I'm off-line, NOT by pulling
    up a page from the internet, such as the above example.
    
    Is this any longer possible?
    
    Trying to figure out how to do this, I see messages such
    as "You need to install the perl-doc package to use this program."
    
    These fail to find or to install anything useful:
      apt install perl-doc
      apt install perldoc
      apt search perldoc
      apt search perl-doc
      aptitude install perl-doc
      aptitude install perldoc
      aptitude search perldoc
      aptitude search perl-doc
      cpan -i perl-doc
      cpan -i perldoc
    
    If it's any longer possible to download full perl documentation
    onto my computer's hard drive, I'd like to know what it is.
    
    My thanks in advance for any suggestions.
    
    Very truly yours,
    
    jf02ir@gmail.com
    
IP address can't recognize by Net::Ping
5 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 23, 2023 at 22:55
    Hi monks,

    I've found Net::Ping can't recognize IP but DBI can:

    $IP = "192.168.0.1 192.168.0.2 192.168.0.3"; for my $ip_addr (split /\s/, $IP){ my $p = Net::Ping->new(); if ($p->ping( $ip_addr )) { $my_state->{IP_stat} = 'UP'} #can't ping else{ $my_state->{IP_stat} = 'unreachable'; next; } $p->close(); my $dbh = DBI->connect("dbi:" . $db_type . ":" . $ip_addr . "/" . $ser +vice_name, $sysUser, $sysPass ); #can connect
    I guess Net::Ping treat varaible as number not string , but DBI don't. is there a way to resolve it ? Thanks

    s

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":


  • 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?
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 musing on the Monastery: (3)
As of 2024-04-25 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found