Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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
Applying regex to each line in a record.
7 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
1 direct reply — 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.
OT: Emacs on Mac Catalina?
4 direct replies — Read more / Contribute
by karlgoethebier
on Oct 22, 2020 at 13:21

    Hi all,

    After upgrading my Mac to 10.15.7 (19H2) AKA Catalina unfortunately i had to find out that Emacs is no longer available.

    I couldn't find a version/recipe in a hurry to get my favorite editor back.

    Thank you very much for any hint. Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Any reason to use the Paws module over aws cli commands in perl script?
5 direct replies — Read more / Contribute
by nysus
on Oct 21, 2020 at 09:25

    What are the arguments for using the Paws module instead of just embedding commands like `aws ec2 run-isntances --image-id ....` into my perl script? I feel dirty just executing command line commands in my perl script and it doesn't feel very professional, but what's the harm, really?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

BEGIN Win32::Daemon
1 direct reply — Read more / Contribute
by PerlAddict42
on Oct 21, 2020 at 04:41
    Using Perl for over 20 years, today I got surprised by something I don't understand. On Windows 10, using Strawberry Perl 5.22, I run the following one-line script from which I expect no output:

    use Win32::Daemon;

    But, surprise, this is the output:

    BEGIN Win32::Daemon ... require Exporter; require DynaLoader; bootstrap Win32::Daemon; done END Win32::Daemon ... DONE Win32::Daemon ...

    This output goes to STDOUT, not to STDERR, and I would like to get rid of it. What am I missing?

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 imbibing at the Monastery: (3)
    As of 2020-10-25 06:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (249 votes). Check out past polls.

      Notices?