Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Seekers of Perl Wisdom

by gods
on Sep 07, 1999 at 20:28 UTC ( #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
dies with no message
2 direct replies — Read more / Contribute
by kp2a
on Sep 29, 2016 at 16:49
    program dies first line afer use statement even a blank line with no message except line number how to debug? perl -c reports systax OK both calling and called program
eval system timeout child process
2 direct replies — Read more / Contribute
by dasibre
on Sep 29, 2016 at 15:22

    New to perl trying to fix zombie process bug.I have a script that makes a timed system call in an eval block.

    my $timeout = timed_system_call("/subprocess_a.rb", 3); if ($timeout == 0) { print "success\n"; } else { print "timed out\n"; } sub timed_system_call { my $command = shift; my $timeout = shift; # seconds my $alarm = 0; eval { local $SIG{ALRM} = sub {$alarm = 1; kill -15, $child_pid;}; alarm $timeout; system($command); alarm 0; }; die $command . " failed with " . $@ if $@ && $alarm != 1; #if alar +m is not 1, then something else caused exit e.g(ctrl-c) alarm 0; return $alarm; }
    I need to, ensure the system() call subprocess is killed after timeout, without killing the parent process. On timeout the program should continue to the else block.
Loop through array or filehandle
3 direct replies — Read more / Contribute
by markdibley
on Sep 29, 2016 at 09:57
    Hello

    I have a subroutine that loops through some data in a file until it has found the correct outcome and then stops. I simply pass a filehandle reference to the subroutine to do it.

    However, I now have a new source of data that gives it to me in a smaller string. To apply the some routine I just need to split the data by \n and could pass the array reference to the subroutine.

    But is there a way to write a subroutine that takes either a filehandle ref or array ref to loop through?

    I am looking for a way that does not involve reading the whole file into a string (although I admit this may because I am old and started programming computers that had never heard of GB memory).

    Is it possible?
Inconsistent errors when trying to establish SSL-connection
1 direct reply — Read more / Contribute
by ddominnik
on Sep 29, 2016 at 09:01

    I'm writing a Perl application to test the REST API of a JIRA server we're using. Somehow I can't seem to be able to establish an SSL connection to the server. I have the following code

    use strict; use warnings; use LWP; use JIRA::REST; my $browser = LWP::UserAgent->new; $browser->proxy(['http','https'],'http://myproxy:8080'); $browser->agent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20 +100101 Firefox/38.0"); my %client = ('useragent' => $browser); my $clientref = \%client; my $jira = JIRA::REST->new('https://myurl:8443/jira', 'myuser', 'mypas +s', $clientref); print $jira->GET("/issue/myissue");
    I had to edit some parts because of confidentiality.
    When I try to run this simple script I get the following error message:
    Can't connect to myurl:8443 (certificate verify failed) LWP::Protocol::https::Socket: SSL connect attempt failed error:1409008 +6:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +at /home/myhome/perl5/lib/perl5/LWP/Protocol/http.pm

    The strange thing is, that this error message is not consistent. F.e. just a few minutes ago it gave me this error without editing anything in the script

    JIRA::REST Error[500 - Internal Server Error]: SSL negotiation failed: error:1406D0CB:SSL routines:GET_SERVER_HELLO:p +eer error no cipher at /home/myhome/perl5/lib/perl5/LWP/Protocol/http +.pm

    I assume that my script isn't able to fetch the certificate from the server, but how do I edit my script to make it at least connect for now?
    I've tried debugging with the analyze-ssl.pl, but it doesnt work either, as the script doesn't accept the syntax of my proxy. I've tried reprogramming it, but without success.

Maintainance of element order in hash
3 direct replies — Read more / Contribute
by ravi45722
on Sep 29, 2016 at 08:42

    I am giving a small snippet of my code. I am pushing elements into the hash in this way.

    $main_hash{"query"}{"filtered"}{"query"}{"bool"}{"must"} = \@file_arra +y; $main_hash{"query"}{"filtered"}{"filter"} = $condition_array[(int($con +dition)-1)];

    I need the query in the first place. But getting the filter in the first place. How to bind the query in first place???? Expected output (After changing into JSON):

    { "query": { "filtered": { "query": { "bool": { "must": [ {"wildcard": { "path": "/home/GEMS/CDRS/Delivery/ravi_16051820*.log" } } ] } }, "filter": { "bool": { "should": [ { "term": { "OrigInterface": "SMPP" } }, { "term": { "OrigInterface": "SMPP" } } ] } } } } }

    Actual output

    { "query": { "filtered": { "filter": { "bool": { "should": [ { "term": { "OrigInterface": "SMPP" } }, { "term": { "OrigInterface": "SMPP" } } ] } }, "query": { "bool": { "must": [ {"wildcard": { "path": "/home/GEMS/CDRS/Delivery/ravi_16051820*.log" } } ] } } } } }
How can I persuade MakeMaker to install a file in $installarchlib/auto/...
1 direct reply — Read more / Contribute
by markt
on Sep 29, 2016 at 05:02

    I am using SWIG to wrap functions from a C library (libX.a) and producing a shared object (Y.so) and a Perl module (Y.pm).

    Neither the library C code nor the library object files are available on the target platform so the shared object is created outwith MakeMaker. The Makefile.PL is written to create the distribution tarball so that the usual rules apply on `make install`.

    However the shared object is installed in the same directory as the Perl module and Dynaload is unable to find the required symbols.

    Looking at other Makefie.PL flles from modules that do install a shared object in the correct place there is no explicit mechanism to place such a shared object. The magic seems to be enabled by defining values for LIB (or some such variable).

    Please could someone tell me where to look in MakeMaker code (whilst I start at the top and go on until the end).

    TIA

    MarkT
PDF to Text
2 direct replies — Read more / Contribute
by 9mohit2
on Sep 29, 2016 at 01:29
    Hi, I want to convert PDF to text format keeping the positions of the text same as PDF so as I can easily get the required data. I have seens posts recommending to use pdftotext and Poppler but can someone help me how can I setup these on a Windows 10 machine. Not getting any clear discussion on installation or usage on any of these. Exampoles would be very useful. Do let me know if any other way is possible. Thanks in Advance.
Is that anyway to override -X functions?
1 direct reply — Read more / Contribute
by exilepanda
on Sep 29, 2016 at 00:48
    Dear monks,

    I've read the perldoc CORE, but it didn't mention if I can or cannot override -X (ie. -f, -d, -e etc). I tried this

    BEGIN { no strict 'refs'; *{'CORE::GLOBAL::-f'} = sub { print "-f called"; } }
    but this won't work. I am trying to build a set of functions that deals with Unicode dirs and files, while maintaining the native syntax. I can override chdir, readdir and sort of, but can't -X. Any clue ?
Error : can't locate object method "createElement" via package XML::DOM::ELEMENT
1 direct reply — Read more / Contribute
by ankit.tayal560
on Sep 29, 2016 at 00:33

    I've written above code to modify the contents of my xml file. but when I tried to create new elements named "item" and "data" it showed me an error : can't locate object method "createElement" via package XML::DOM::ELEMENT. how can I get rid of this problem? any suggestions? it is giving me an output window of Joey 67890 4 and then an error pops up which I just mentioned above

    use strict; use warnings; use Data::Dumper; use XML::DOM; my $parser=new XML::DOM::Parser; my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin.xml') or die$!; my $root=$doc->getDocumentElement(); my @address=$root->getElementsByTagName("address"); foreach my $address(@address) { if($address->getAttribute("name") eq "tayal") { if($address->getAttribute("id")=='70889') { $address->setAttribute("name","Joey"); $address->setAttribute("id","67890"); $address->setAttribute("flags","4"); my $temp1=$address->getAttribute("name"); my $temp2=$address->getAttribute("id"); my $temp3=$address->getAttribute("flags"); print("$temp1\n\n"); print("$temp2\n\n"); print("$temp3\n\n"); my $temp_item=$root->createElement("item"); my $temp_data=$root->createElement("data"); my $child1=$address->appendChild($temp_item); $child1->setAttribute("used","1"); $child1->setAttribute("order","0"); my $g=$child1->getAttribute("used"); my $h=$child1->getAttribute("order"); print("$g\t$h\n"); my $child2=$child1->appendChild($temp_data); $child2->setAttribute("typeid","4"); my $k=$child2->getAttribute("typeid"); print("$k\n"); } } } $doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8')); $doc->printToFile("C:/perl/perl_tests/xmlin2.xml"); $doc->dispose; XML FILE : <config logdir="var/log/foo/" debugfile="tmp/foo.debug"> <server name ="sahara" osname ="solaris" osversion="2.6"> <address name="ankit" id="70888"/> <address name="tayal" id="70889"/> </server> <server name="gobi" osname="irix" osversion="6.5"> <address name="anshul" id="70689"/> </server> <server name="kalahari" osname="linus" osversion="2.0.34"> <address name="raghu" id="45678"/> <address name="lucky" id="67895"/> </server> </config>
My local libs are not being used by my browser
3 direct replies — Read more / Contribute
by Lady_Aleena
on Sep 28, 2016 at 19:50

    Hello all. I am having a problem with my browser not recognizing my local libs. I set them up because I was told installing modules with sudo cpan and putting them in the main libs was not great. So I set up my local libs and installed all kinds of modules into them, got apache set up so I could view my website in my browser, but the browser does not use my local libs.

    Here is the result of perl -e 'print "$_\n" for sort @INC' on the command line:

    . /etc/perl /home/me/Documents/fantasy/files/lib /home/me/perl5/lib/perl5 /home/me/perl5/lib/perl5/5.20.0 /home/me/perl5/lib/perl5/5.20.2 /home/me/perl5/lib/perl5/5.20.2/x86_64-linux-gnu-thread-multi /home/me/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/local/lib/site_perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/share/perl/5.20 /usr/share/perl5

    Here is the list of libs my browser is looking in:

    files/lib /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.20.2 /usr/local/share/perl/5.20.2 /usr/lib/x86_64-linux-gnu/perl5/5.20 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.20 /usr/share/perl/5.20 /usr/local/lib/site_perl

    I ran echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >>~/.bashrc at the command line, and it added the following lines to my .bashrc file:

    PATH="/home/me/perl5/bin${PATH:+:${PATH}}"; export PATH; PERL5LIB="/home/me/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export P +ERL5LIB; PERL_LOCAL_LIB_ROOT="/home/me/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCA +L_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT; PERL_MB_OPT="--install_base \"/home/me/perl5\""; export PERL_MB_OPT; PERL_MM_OPT="INSTALL_BASE=/home/me/perl5"; export PERL_MM_OPT; eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"

    I already have several PATH statements above these lines and a PERL5LIB line, so I do not know if there is a conflict. Here are the lines:

    # My changes to things # export LC_ALL=C export LC_COLLATE=C export LESS=-SXi export PERL5LIB="$HOME/Documents/fantasy/files/lib" PATH="$PATH:$HOME/bin" PATH="$PATH:$HOME/Documents/fantasy" PATH="$PATH:$HOME/Documents/scripts" export PATH setterm --linewrap off

    So can anyone tell me what I am missing here?

    Thank you!

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

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 perusing the Monastery: (3)
    As of 2016-09-30 05:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Extraterrestrials haven't visited the Earth yet because:







      Results (562 votes). Check out past polls.