Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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. Post a new question!

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.

User Questions
Why server error out with module
3 direct replies — Read more / Contribute
by keen2learn
on Oct 26, 2020 at 08:34
    New to perl modules, I have the issue where, my perl script calls in a perl module. I get one of three responses when I load that script: 1. error 500 page 2. error Undefined subroutine called 3. the correct output, though lately that isn't happening at all :( The resultant pages seem to rotate between the three (above) and my ISP assured my last week, they had disabled caching, which at that time was identified as the cause. What else could be stopping this module from working? here's the calling script: login.pl
    #!/usr/bin/perl -w use strict; use warnings; use CGI; use Data::Dumper; my $cgi = new CGI; BEGIN{ unshift @INC, "/var/www/vhosts/myDomain.com/secured.myDomain.com +/cgi-bin/library"; } print $cgi->header; use doctypeAndHeader; header();
    And, here's the module called doctypeAndHeader.pm
    package doctypeAndHeader; use strict; use warnings; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = ("header"); sub header{ my $doctypeAndHeader = ''; $doctypeAndHeader = getDoctypeAndHeader(); print qq($doctypeAndHeader); } sub getDoctypeAndHeader{ # configs my $pageTitle = 'Bangor Town Centre'; #my $scriptUrl = $ENV{"SCRIPT_NAME"}; #my @scriptNameArray = split( '/' , $script_url); #my $scriptName = $scriptNameArray[-1]; my $doctypeAndHeader = "<!doctype html> <html> <head> <title>$pageTitle</title> </head> <body></body> </html>"; return $doctypeAndHeader; } 1;
Perl Zlib last block
1 direct reply — Read more / Contribute
by Kroning
on Oct 26, 2020 at 07:36

    Hi!

    I have some packet from app that looks like "ec bd ... 00 00 ff ff" which I am trying to decode.

    From what I have found, it looks like "00 00 ff ff" is a Z_SYNC_FLUSH of deflate (zlib).

    I tried to reproduce it on Compress::Raw::Zlib, Compress::Zlib and some others. But the ending pattern was "00 ff 00 ff". Am I missing something?

    #!/usr/local/bin/perl use Compress::Zlib ; my $x = deflateInit() or die "Cannot create a deflation stream\n" ; ($output, $status) = $x->deflate('text') ; ($output, $status) = $x->flush(Z_SYNC_FLUSH) ; $output =~ s/(.)/sprintf '%04x', ord $1/seg; print "output=$output\n";
    output=002a004900ad0028000100000000000000ff00ff00000000000000ff00ff
Request your guidance. Please do not take it otherwise.
13 direct replies — Read more / Contribute
by netizen
on Oct 25, 2020 at 13:13

    Hi Monks,

    I've visited in this forum in the past once in a while as back then I used to write some small scripts. Always preferred Perl over Python.

    My question is not sarcasm, nor am I trying to troll you esteemed monks. It is a genuine question. This is a forum where most of you are quite mature and understanding folks and therefore I am hoping I will not be admonished for asking this question.

    The question is, considering the current job scenario, especially in the automation field, do you guys think it makes sense to learn Perl or Python? I see the internet rife with articles stating the decline of my favourite language, and I also see a lot of demand for Python but not for Perl and therefore I ask this question - In today's job scenario, would it make sense to learn Perl? Are there any jobs available in Perl? Ofcourse knowing both Perl and Python would be great, but, I would rather start with 1 language, know it really well before I make the jump.

    Or, would it now make sense to learn Perl as there's lesser folks into Perl than earlier so it will be sort of a niche skill?

    Please do guide me.

Applying regex to each line in a record.
9 direct replies — Read more / Contribute
by pritesh_ugrankar
on Oct 24, 2020 at 14:40

    Hi Monks,

    Even after multiple attempts, I am at a total loss of how the "m" and "s" works for regex. I have a file like this:

    first: this:that here:there when:what how:where now:later second: this:that here:there when:what how:where now:later

    Please note that in the example, "this:that", "here:there", etc are repeated, but that's not the case with the actual record I am working on. I am trying to write a script that will create a hash of hashes such that I get a hash with a key "first" and its value will be a key value pair such that the key will be "this" and value will be "that", key will "here" and value will be "there", and so on and so forth. But even before I reach there, I need to ensure that I write the correct regex. So, I tried to write a regex that will skip the line if it contains "first" or "second". Of course if the regex works, I can then capture the part and make that as a hashkey, but that's much later.

    I've tried the following, but it does not work. And I am pretty sure it's because my utter failure to understand how "m" and "s" work.

    use strict; use warnings; use Data::Dumper; my $file = "new_testfile.txt"; my $testhashref; open (my $fh, "<",$file) or die "Can't open open file $file:$!"; { local $/ = ""; while (my @records = <$fh>) { foreach my $line (@records) { next if $line =~ /^[a-z]+:$/m; print "$line"; } } }

    I tried using "s" instead of "m", but when I run the script, it does not read anything.

    pritesh@pavilion:~/perlscripts$ perl test.pl pritesh@pavilion:~/perlscripts$

    If I remove the next if $line =~ /^[a-z]+:$/m;, I get the whole file like so:

    pritesh@pavilion:~/perlscripts$ perl test.pl first: this:that here:there when:what how:where now:later second: this:that here:there when:what how:where now:later

    So at least I know it's reading the records right. I will be thankful if you could help me with this one.

int() function
5 direct replies — Read more / Contribute
by geoperl
on Oct 24, 2020 at 06:45

    Hi Monks

    I came across with a strange result when I'm using int() function. For example,

    my $x1 = (1.15*170)+0.50; my $x2 = int($x1); print "Number is: $x1, Integer part is: $x2";

    It prints "Number is: 196, Integer part is: 195", but I would expect $x2 to be 196

    But when I am using different numbers I am getting the correct results. For example,

    my $x1 = (1.15*150)+0.50; my $x2 = int($x1); print "\nNumber is: $x1, Integer part is: $x2";
    my $x1 = (1.15*30)+0.50; my $x2 = int($x1); print "\nNumber is: $x1, Integer part is: $x2";

    Can anybody guess what goes wrong with the first one, what goes wrong when I'm using the number 170? At least, I would expect either all results be correct or all results be wrong, but not just one be wrong.

    Using int(sprintf("%.2f",$x1)) fixes the error but this is not the issue.

[OT] How to make a second github PR
3 direct replies — Read more / Contribute
by syphilis
on Oct 24, 2020 at 04:28
    Hi,

    I've already got an open perl5 pull request that I'm not ready to close just yet.
    Now I want to open a second perl5 pull request on a separate issue, involving different files - namely win32/makefile.mk and win32/GNUmakefile.

    I've done some googling, and found that one way to do that would be to create a new branch and make the changes to the makefiles in it.
    But I don't think that will work because the changes I've made in my current pull request were made in my fork's master branch - whereas they would have to have been made in a different branch, if I was ever going to make a second pull request without closing the first.
    So, I'm thinking I might have snookered myself through lack of foresight.

    The only solution that I can think of is to use a second github account with a second fork, in order to make this second pull request.
    That's not something I really want to do. Is there another way ?

    Cheers,
    Rob
Soap Call fails
1 direct reply — Read more / Contribute
by PerlMASA
on Oct 23, 2020 at 23:24

    I am trying to call a Soap Webservice.I have to pass the name of a Code table (for eg STATE_CODES) and it returns key value pair like NY - New york, DE-Delaware etc.

    #!/usr/local/bin/perl use strict; use warnings; use Data::Dumper qw<Dumper>; #use SOAP::Lite trace=>'all'; use SOAP::Lite +trace =>'debug'; #use SOAP::Lite; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 1; #my $wsdl = 'https://dev1:2001/ACTS?wsdl'; my $endpoint = 'https://qa1:2001/ACTS'; my $wsdl = 'HTTPS://QA1:2001/ACTS?wsdl'; my $method_name = 'impl:getCodes'; my $uri = 'http://impl.webservice.acts.ito.aoc.nj'; my $ns = 'http://impl.webservice.acts.ito.aoc.nj'; my $client = SOAP::Lite->new( proxy=>$endpoint, service=>$wsdl, readable=>1 ); $client->outputxml(1); $client->envprefix('soapenv'); $client->ns($uri,'impl'); $client->outputxml('true'); my @param; push @param, SOAP::Data->name("codeTable"=>'STATE_CODES'); my $soapResp = $client->call($method_name,@param); print $soapResp; print "\n";

    output is as below
    root@np1 ~# perl /test/soaptest6.pl
    SOAP::Transport::HTTP::Client::send_receive: POST https://qa1:2001/ACTS HTTP/1.1
    Accept: text/xml
    Accept: multipart/*
    Accept: application/soap
    Content-Length: 580
    Content-Type: text/xml; charset=utf-8
    SOAPAction: "http://impl.webservice.acts.ito.aoc.nj#getCodes"

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope
    soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:impl="http://impl.webservice.acts.ito.aoc.nj"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <impl:getCodes>
    <codeTable xsi:type="xsd:string">STATE_CODES</codeTable>
    </impl:getCodes>
    </soapenv:Body>
    </soapenv:Envelope>
    SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 Error
    Connection: close
    Content-Type: text/xml; charset=utf-8
    Client-Date: Sat, 24 Oct 2020 02:46:04 GMT
    Client-Peer: 192.168.248.33:2001
    Client-Response-Num: 1
    Client-SSL-Cert-Issuer: /CN=qa1
    Client-SSL-Cert-Subject: /CN=qa1
    Client-SSL-Cipher: ECDHE-RSA-AES256-GCM-SHA384
    Client-SSL-Socket-Class: IO::Socket::SSL
    Client-SSL-Warning: Peer certificate not verified
    X-Backside-Transport: FAIL FAIL

    <?xml version='1.0' ?>
    <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Body>
    <env:Fault>
    <faultcode>env:Client</faultcode>
    <faultstring>Internal Error</faultstring>
    </env:Fault>
    </env:Body>
    </env:Envelope>
    <?xml version='1.0' ?>
    <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
    <env:Body>
    <env:Fault>
    <faultcode>env:Client</faultcode>
    <faultstring>Internal Error</faultstring>
    </env:Fault>
    </env:Body>
    </env:Envelope>

    The soap request kind of looks good, but it gives error. I pasted the soap request into SOAPUI from the soapActionand it worked.

    Why is my soap request resulting in failure. is it because of some certificate issue. i believe i have asked the code to skip certificate validation and Client-SSL-Warning: Peer certificate not verified in output above is just a warning and can be ignored

    Is the line between getCodes" and <?xml version="1.0"... in soapAction causing failure. The request failed in SOAPUI if I added a line before the <?xml version="1.0"...

    if it helps, the soap webservice is a java application on websphere and it is being accessed by perl through datapower.

SOAP Client package
2 direct replies — Read more / Contribute
by PerlMASA
on Oct 23, 2020 at 22:33

    I am a newbie to perl and trying to figure out what is better to use.

    I have seen three suggestions

    soap::lite
    soap::wsdl
    xml::compile

    Soap::lite seems to have been around longer, but seems to be difficult to use with more complex wsdl and services. I will be calling a service that adds a document (bytes) with a lot of metadata.

    I had looked at some other sites for help and in one of the site some one had mentioned that xml::compile is dead.

    Which is the better package to use to call soap webservice. I am not able to figure out which module/package is continuously supported and developed.

select RBITS,WBITS,EBITS,TIMEOUT. The meaning of all the *BITS
2 direct replies — Read more / Contribute
by igoryonya
on Oct 22, 2020 at 20:38
    I am reading documentation on select command and I can't figure out, what these RBITS,WBITS,EBITS mean.

    Well, I came to guess, that probably, RBITS - means Read Bits, WBITS - Write Bits, but what about EBITS, then?
    What does this construct mean? What is it used for? Manual doesn't explain anything. Just throws these:

    select RBITS,WBITS,EBITS,TIMEOUT
    my ($nfound, $timeleft) = select(my $rout = $rin, my $wout = $win, my $eout = $ein, $timeout);
    
    without any explanation.
Trim Two Characters On Line
5 direct replies — Read more / Contribute
by jalopez453
on Oct 22, 2020 at 18:55
    Would someone be able to assist me in regards to updating a line when it meets a certain criteria. I am looking for something along the lines of.
    if LINE contains "SUM" then remove last two characters in line ELSE #do nothing END IF
    I have read many forums but I can't seem to find something of what I am trying to complete.

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, 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, 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
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2020-10-27 10:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (256 votes). Check out past polls.

      Notices?