Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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
backtick iterpolation issue
7 direct replies — Read more / Contribute
by idlehands
on Jul 01, 2015 at 08:58

    I'm trying to use backticks to run ls to search for files to gather a list of files that exist. End goal is to parse a group of iTune's playlist files to make sure when import the playlists to itunes it won't drop files if they don't exist. My problem is when I run ls in backticks with the file name, a \r is post pended to the command. making every file show up as not found.

    $playListRow = quotemeta($playListRow); my $lscom = "ls $playListRow 2>&1"; my $result = `$lscom`;

    this outputs: ls: /Volumes/public_files/music/ABC - The Lexicon of Love (1982) {1996 Remaster} Look Of Love (Live).mp3\r: No such file or directory

    No matter how I fiddle with it I can't get the \r to go away. Thanks!

How to extract a sentence?
2 direct replies — Read more / Contribute
by vijayraman
on Jul 01, 2015 at 04:26
    I'm trying to fetch sentences from HTML using HTML::treeBuilder. I could parse upto the div but didnt know how to write the regex for matching a sentence. Can u help me?.Thanks in advance.
how to watch source code debugging with Apache:DB ?
No replies — Read more | Post response
by jjmoka
on Jul 01, 2015 at 04:12
    I'm playing around Apache::DB to remotely debug scripts running under mod_perl-2. I can have an interactive debugging session, but when I finally reach my code there is no way to print symbols or even only a pretty listing of source lines. Did any Monk ever succeed to use effectively Apache::DB inspecting his own vars ?
    http.conf: HTTPD='/usr/sbin/httpd -X -DPERLDB -f ~/debug.d/simple.conf' simple.conf: PerlModule ModPerl::PerlRun <IfDefine PERLDB> PerlRequire ~/handlers/ </IfDefine> <Location /> SetHandler perl-script PerlHandler ModPerl::PerlRun <IfDefine PERLDB> PerlFixupHandler Apache::DB </IfDefine> Options +ExecCGI PerlSendHeader On PerlSetupEnv On Order allow,deny Allow from all </Location> ~/handlers/ use APR::Pool(); use Apache::DB (); Apache::DB->init();
Efficient split for alpha numeric pairs in a row
5 direct replies — Read more / Contribute
by merrymonk
on Jul 01, 2015 at 03:12
    I need to analyse data used to control machine tool. A sample is shown below. Each item in the row is a letter followed by a number which can be either an integer or real.
    For each row I want to split the data so that in a hash I get, for example, for the first row
    $h{N} = 260; $h{G} = 02 ; $h{X} = 142.05; $h{Y} = 649.62; $h{I} = 77.33; $h{J} = 58.34; $h{H} = 2; $h{M} = 25;

    N260G02X142.05Y649.62I77.33J58.34H2M25 N265M20 N270G45 N275G01X304.78Y608.8C45.91M25 N280M20 N285G46C0 N290G03X324.39Y638.4I-69.58J67.4H2M25 N295M20 N300G45 N305G01X180.04Y592.89C326.5M25 N310X279.77Y586.78C26.5 N315X195.39Y584.57C336.5 N320X228.31Y579.58C355.92

    What is the most effective way of using Perl to ‘split’ the data so I can create the hash?
how to create output file using perl
4 direct replies — Read more / Contribute
by vineetha
on Jul 01, 2015 at 02:56
    I have two files. One file contains blast result of contigs and the next file contains the contigs that are used for blast.

    I want an output text file of sequences in a separate folder which gives no hits in blast result from original fasta file with all contigs.

    I have no idea about this. Can you please help me to create perl script for this problem.
v5.22.0: Redundant argument in %s versus minimum width in sprintf
2 direct replies — Read more / Contribute
by JadeNB
on Jun 30, 2015 at 23:39
    Hi, folks! I recently saw a post on TSE about an apparent incompatibility between v5.22.0 and TeXLive's tlmgr progamme. Based on the description in the self-answer, it seems that (some of) the problem is that lines 3109–3110 of tlmgr say:
    info("[" . sprintf ('%*2$s', $currnr, $totalnrdigits) . "/$totalnr, $estrem/$esttot] update: $pkg [${kb}k] ($rev -> +$mediarevstr)");
    and that this produces the error Redundant argument in sprintf at /usr/local/texlive/bin/tlmgr line 3109. Based on Redundant argument in s Redundant argument in %s, this is because of, well, a redundant argument in sprintf—I guess it's bothered by the fact that two strings are passed, but only one is referenced. However, sprintf lists almost this exact useage as recommended. Is this a (Perl) bug, or perhaps just a lag between online documentation and the latest version (as evidenced by the fact that perldoc online doesn't currently know about this new error message!); and / or is there some appropriate work-around?
Position in seek() confusion
5 direct replies — Read more / Contribute
by stevieb
on Jun 30, 2015 at 21:25

    I've never had a need to use seek() in my Perl years, so after I got looking at a piece of code BrowserUK posted earlier today, I thought I'd ask about it.

    In the below code in the seek $fh, $_ *80, 0; line, I would believe that it would set the cursor to column 80 (times the multiple in the while(...)), but it then proceeds to print 78 chars to the file. When I look at the file, all lines start at column 0.

    #! perl -slw use strict; use threads; open my $fh, '>', 'junk.dat' or die $!; $_->join for map { async { seek $fh, $_ *80, 0; print $fh $_ x 78; }; } 1 .. 4; close $fh; open $fh, '<', 'junk.dat' or die $!; print while <$fh>; close $fh;

    perldoc -f seek doesn't help it click for me. Can someone advise what I'm missing in the above code? I did modify the code to try to understand, but the reason why things start at col 0 elude me.


A dreaded SOAP server with ws-security
3 direct replies — Read more / Contribute
by SuperSparky
on Jun 30, 2015 at 14:11

    I have been pulling my hair out with this one, and it shouldn't be too difficult (but then again, when is SOAP simple?). I have been tasked with coding a SOAP server (NOT client) that incorporates WS-Security. I realize everyone must be pointing and laughing by now, but I have no choice with this. I've used the sample code in the SOAP::Lite docs as a starting point, but it always rejects ANY transaction with " mustUnderstand="1" " in it. I turn that off, I am able to read the header and process the WS header myself, but with that on, I don't get that far. SOAP::Lite just bounces it back saying it doesn't understand.

    So... How do I get SOAP::Lite to "understand" or at least accept the envelope and give me a SOM to work with?

    Please keep in mind I HAVE to write this server according to WSDL, and sample envelope given to me, as this is how the (very large) customer's system works. I also cannot tell them to turn off "mustUnderstand" either.

    Luckily, their authentication mechanism is only "passwordText", so no need for decryption etc, as it is on HTTPS. I just need to get to the header once a SOM is given to me is all. I need to make SOAP::Lite ""understand" what it doesn't understand, and I cannot find anything anywhere about WS-Security for SERVERS. There's a boat load about clients, but nothing on servers.

    Here's the sample posted envelope I am to make work (without the body for disclosure reasons):

    <soapenv:Envelope xmlns:soapenv=""> <soapenv:Header> <wsse:Security xmlns:wsse=" +00401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"> <wsse:UsernameToken wsu:Id="unt_5KBJ2WZxfTuiyZqf" xmlns:wsu=" +s-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:Username>SA_User</wsse:Username> <wsse:Password Type=" +-200401-wss-username-token-profile-1.0#PasswordText"> sa </wsse:Password> <wsse:Nonce>MC45NzcwNjA5MTgyMDk2OTIz</wsse:Nonce> <wsu:Created>2010-08-31T20:56:14Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> blah... blah... blah... </soapenv:Body> </soapenv:Envelope>

    This is my test server code running as a CGI on Apache

    use strict; use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI ->dispatch_to('Quote') ->handle; BEGIN { package Quote; use vars qw(@ISA); @ISA = qw(Exporter SOAP::Server::Parameters); use SOAP::Lite; use Data::Dumper::Simple; sub GetQuote { my @params = @_; print STDERR Dumper(\@params); return('ok'); } }

    This is my test code to send my test envelope:

    use strict; use LWP::UserAgent; use HTTP::Request::Common; my $ua = LWP::UserAgent->new(agent => 'perl post'); my $file = $ARGV[0]; my $msg = slurp_file($file); my $resp = $ua->request(POST 'http://localhost/perl/server.cgi', Content_Type => 'text/xml', Content => $msg); print $resp->error_as_HTML unless $resp->is_success; print $resp->as_string; exit(0); sub slurp_file { my $file = shift; # Read in a text file without using open return(do { local( @ARGV, $/ ) = $file ; <> }); }

    Here's the response back:

    <?xml version="1.0" encoding="UTF-8"?><soap:Envelope soap:encodingStyl +e="" xmlns:soap="http://sche" xmlns:soapenc="http://schemas.xmlsoap" xmlns:xsd="" xml +ns:xsi=""><soap:Body><soap:F +ault><faultcode>soap:MustUnderstand</faultcode><faultstring>Unrecogni +zed header has mustUnderstand attribute set to 'true'</faultstring></ +soap:Fault></soap:Body></soap:Envelope>

    I REALLY don't want to have to create my own SOAP handler to get around this. I'm hoping for some override, something.

wild cards in Vertica
3 direct replies — Read more / Contribute
by pragov
on Jun 30, 2015 at 14:00
    Hi All,

    I have a perl-Vertica question. I need to pass a combination of a wild card and complete value of a field. It will be a combination of prefix and others. The example is ('A','BCD-UT1','MDO-CT1'). The actual value of A is ABC-EF2.But users can just click on Prefix,A to get all values starting with A. I tried,

    if ($clnm ne ""){ $cnt = @parts = split(/\,/, $ clnm ); $clnm = "'"; for ($i = 0; $i < $cnt; $i++) { $clnm = $clnm . $parts[$i]; ($clnm = $clnm . "%','") if ($i < $cnt - 1); } $clnm = $clnm . "%'"; } and then used it in if ($clnm ne "") { $Where = $Where . "AND m.CLNAME LIKE $clnm %’ OR m. +CLNAME IN ($clnm ) "; }.

    It is not working. The SQL either takes LIKE('A%') or IN ('ABC-EF2','BCD-UT1','MDO-CT1'), but not the combination. How to retrieve the value,('A','BCD-UT1','MDO-CT1')?

    Thanks, pragov
CGI to redirect using sessions
3 direct replies — Read more / Contribute
by lewars
on Jun 30, 2015 at 13:24

    We have built a simple Perl CGI to allow us to check for SiteMinder SM Session cookies, variables passed in the URI and to redirect the browser to our Federation server while maintaining the Federation Session ticket.

    The requestor will be sent to an error page if any of these conditions exist:

  • If no SiteMinder SM Session is provided there is an error
  • If no Resume Path is set, meaning there is no Ping Federation ticket
  • If browser posts the request and was already sent to the script within 15 seconds, indicating a loop
  • I have used several code examples on Perl Monks, forgive me for not detailing each one in the script below....

    I will gladly accept any tips to make the code more terse/concise, thanks in advance!

    The script is hosted on Apache and is executed called like the following:

  • https://localhost/wrp/
  • #!/usr/bin/perl # # PROGRAM: # # PURPOSE: This script checks the request for cookies and environ +ment variables and redirects customer # back to the federation environment with good session # CREATED: June 30, 2015 by Mitchell Lewars # Thanks for help to Björn Vildljung # Lots of examples used from Perl Monks web site use CGI qw(:standard); #use warnings; $query = new CGI; $perror = 0; #//Set to 1 in case of an error. $wearelooping = 0; #//Set to one if a user returns withing 15 secon +ds, indicating a redirect-loop. $redirectURL = ""; #---- Next get the current values $gotcookies = $ENV{"HTTP_COOKIE"}; $env = $query->param('env'); $resumepath = $query->param('resumePath'); #// Check for the env= entry in the URL. If it is set to prod, use pro +d federation, else use QA. if ( $env =~ 'prod') { $redirectURL = " +m"} #// Check that the PF-session information is passed as expected, if no +t, we got an error. Otherwise, add it to redirectURL if ( $resumepath ) { $redirectURL .= $resumepath } else { $perror=1 } # Verify that there is an SMSESSION, otherwise we got somebody accessi +ng us the wrong way, and therefor probably for the wrong reasons. ERR +OR! #$perror = 1; # if customer has no SMSESSION they reached this page in + error if (!( $gotcookies =~ /smsession/i)) { $perror = 1} # Check if there is already an SMPF, if so we are looping if ( $gotcookies =~ /smpf/i) { $wearelooping = 1} #// Check to see if a Cookie named SMPF is avalible. If not, we set it + and give it a 15 second lifetime. If it is there, we got a redirect +loop. if (($wearelooping eq 0) && ($perror eq 0)) { $cookie = $query->cookie(-name=>'SMPF', -value=>'1', -expires=>'+15s', -path=>'/'); print $query->redirect( -cookie => $cookie, -uri => "$redirectURL"); print $query->start_html( -title=>'Login'); print $query->end_html; } else { $cookie = $query->cookie(-name=>'SMPF', -value=>'', -expires=>'now', -path=>'/'); print $query->header(-cookie=>$cookie); print $query->meta(''); print $query->start_html('Login'); print $query->body("<big><big><b>Redirect loop!</b></big></big><b +r><br> You have been assigned a SESSION-cookie, as confirmation that +you have successfully logged in. For some reason the login-servers wh +o needs this cookie is not getting it from your browser, causing a lo +op of redirection. Please try to go back to the site you want to logi +n to and try again. <b>You should not need to enter your credentials +again</b>. If this error is reoccurring for you, try using a differen +t browser."); print $query->end_html; }

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2015-07-03 08:04 GMT
    Find Nodes?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

      Results (49 votes), past polls