Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Extraction of value with XMLLIB
2 direct replies — Read more / Contribute
by shak
on May 05, 2015 at 10:32
    Hi All, I have a Huge XML file I need to extract data below with XMLLIB
    VAL1 ,0,0 VAL2,0,0 VEL3,0,0 VAL4,0,0 VAL5 ,490783914,4532
    My code
    my $parser = XML::LibXML->new(); my $doc = $parser->parse_file($filename); foreach my $book ($doc->findnodes('/mdc/md/mt[text()="VAL1"]') { $val1=$book->findnodes('./r[1]/text ()'); push (@Val,$val1) }
    Input XML File
    <p> <mdc xmlns:HTML=""> <md> <neid> <neun></neun> <nedn>GET_SUB</nedn> <nesw>R4BA06</nesw> </neid> <mi> <mts>20150429141500Z</mts> <gp>900</gp> <mt>VAL1</mt> <mt>VAL2</mt> <mt>VAL3</mt> <mt>VAL4</mt> <mt>VAL5</mt> <mt>VAL6</mt> <mt>VAL7</mt> <mt>VAL8</mt> <mv> <moid>NAME</moid> <r>0</r> <r>0</r> <r>0</r> <r>0</r> <r>490783914</r> <r>0</r> <r>0</r> <r>0</r> </mv> <mv> <moid>NAME1</moid> <r>0</r> <r>0</r> <r>0</r> <r>0</r> <r>4532</r> <r>0</r> <r>0</r> <r>0</r> </mv> </mi> </md> </mdc>
2 direct replies — Read more / Contribute
by bigup401
on May 05, 2015 at 09:41

    when i try to post request to url

    i get this error

    SSLget()_next_proto negotiated could not be located in the dynamic link library SSLEAY32.dll

    use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = new LWP::UserAgent(keep_alive=>1); $responde = HTTP::Request->new(POST => ""); $responde->content_type("application/x-www-form-urlencoded"); $resp = $ua->request($responde);
auto increment
3 direct replies — Read more / Contribute
by PilotinControl
on May 05, 2015 at 09:04

    Good Morning Esteemed Monks!

    My question has to do with auto increments and I think I am missing something very simple as when I add rows to my file the ID should go up by 1 when each new entry is added correct? Please refer to my code below and point me in the right direction as to what I am missing. Thanks in advance!

    my $id = 1; my $output="data.txt"; open(DAT,">>$output") || die("Cannot Open File"); print DAT ($id++); print DAT (":"); print DAT ($name); print DAT (":"); print DAT ($number); print DAT (":"); print DAT ($address); print DAT (":"); print DAT ($phone); print DAT (":"); print DAT ($email); print DAT ("\n"); close (DAT);
[OT] Ordering colors
4 direct replies — Read more / Contribute
by BrowserUk
on May 05, 2015 at 07:15

    Anyone any thoughts/references on how to order the 64 colors in this image so that a group of lines draw in colors picked from an adjacent set of values from the ordered set will stand a reasonable chance of being discernible?

    That is: if you pick (say) 12 adjacent values from anywhere in the ordered set; they'll likely contrast fairly well.

    Someone must have done this, but I haven't found the right set of keywords yet. (I'm fairly particular about this set of colors; unless someone knows of a better set?)

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
exiting a subroutine neatly
3 direct replies — Read more / Contribute
by Mavebe
on May 05, 2015 at 05:26
    I'm using a subroutine to communicate with an SSH host. Each time i post a command i receive a errcode and the return value. If one of those isn't as expected, i exit my subroutine using return. However, before the return, i first have to exit the ssh session and then close the session.
    if (!$ssh->start_session($ssh_host)) { print "ERROR connecting to $ssh_host\n"; return 1; } my ($ret,$err)=$ssh->execute('command1','expect1'); if ($err || $ret=~/Unknown command:/m) { $ssh->exit_session(); $ssh->close_session; return 2; } my ($ret,$err)=$ssh->execute('command2','expect2'); if ($err || $ret=~/Unknown command:/m) { $ssh->exit_session(); $ssh->close_session; return 3; }
    Is there a better way to execute the exit, close and then the return instead of writing them after every statement to get out of the subroutine ? kr
Q: Cannot get the capture from connection with Net::Openssh?
1 direct reply — Read more / Contribute
by ryder
on May 05, 2015 at 03:57

    Heelo Perl Monks,

    I try to connect to a network appliance using Net::Openssh. Simple commands like ls /tmp or cat /etc/hosts are working.

    But I try to capture the output from a proprietary command, called dbedit. The appliance have a standard Openssh server installed, version OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006 The server cannot be updated. here my test programm:

    #!/usr/bin/perl use Net::OpenSSH; my $host = ""; my $user = "admin"; my $pass = "my_pw"; #$Net::OpenSSH::debug=-1; my $ssh = Net::OpenSSH->new(host=>$host, user=>$user, password=>$pass, master_opts => [-v, -o => "StrictHostKeyCh +ecking=no"], ); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error +; my $xxx = "source /opt/CPshrd-R77/tmp/ ; /opt/CPsuite-R7 +7/fw1/bin/dbedit --h"; #my (@ls,$errput) = $ssh->capture2({tty => 1},"/opt/CPsuite-R77/fw1/ +bin/dbedit --h"); my (@ls,$errput) = $ssh->capture2({tty => 1},$xxx); $ssh->error and die "remote ls command failed: " . $ssh->error; print"LS:@ls\n"; print"ERR:$errput\n";

    As you can see by the code. I already tried some hacks to solve the problem. But any additional option I integrated into the code. Did not solve the problem. Interesting ist that the Debug-Output is showing the output from the command, but it seems this output did not get back through the tunnel to the ssh client. Please finde following the debug output from a connection establishment test:

    Is there anybody out there who can help me to capture the output from this command.

    ciao ryder

Problem installing Win32::ToolHelp with Strawbeery Perl Win64
2 direct replies — Read more / Contribute
by tangobaer
on May 05, 2015 at 03:52
    Hello community,
    this is my first question - please be kind.
    I try to install Win32::ToolHelp with x64 Strawberry Perl on Win7 64.
    When I use cpanm I get an dmake error: Build.log:
    cpanm (App::cpanminus) 1.7033 on perl 5.020002 built for MSWin32-x64-m +ulti-thread Work directory is C:\Users\Eurocom/.cpanm/work/1430810127.6240 You have make C:\Strawberry\c\bin\dmake.exe You have LWP 6.13 Falling back to Archive::Tar 2.04 Searching Win32::ToolHelp () on cpanmetadb ... --> Working on Win32::ToolHelp Fetching +tar.gz -> OK Unpacking Win32-ToolHelp-0.32.tar.gz Entering Win32-ToolHelp-0.32 Checking configure dependencies from META.yml Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.04) Configuring Win32-ToolHelp-0.32 Running Makefile.PL Checking if your kit is complete... Looks good MakeMaker (v7.04) Warning (non-fatal): Target 'dynamic' depends on targets in skipped se +ction 'dynamic_lib' Warning (non-fatal): Target 'static' depends on targets in skipped sec +tion 'static_lib' Generating a dmake-style Makefile Writing Makefile for Win32::ToolHelp::Impl Writing MYMETA.yml and MYMETA.json Generating a dmake-style Makefile Writing Makefile for Win32::ToolHelp Writing MYMETA.yml and MYMETA.json -> OK Checking dependencies from MYMETA.json ... Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.04) Building and testing Win32-ToolHelp-0.32 cp blib\lib\Win32\ AutoSplitting blib\lib\Win32\ (blib\lib\auto\Win32\ToolHelp +) cd Impl && dmake gcc -c -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCR +IPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv + -fno-strict-aliasing -mms-bitfields -s -O2 -DVERSION=\"\" +-DXS_VERSION=\"\" "-IC:\STRAWB~1\perl\lib\CORE" Impl.c ar /out:Impl.a Impl.o ar: invalid option -- / Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [member +-name] [count] archive-file file... ar -M [<mri-script] commands: d - delete file(s) from the archive m[ab] - move file(s) in the archive p - print file(s) found in the archive q[f] - quick append file(s) to the archive r[ab][f][u] - replace existing or insert new file(s) into the archi +ve s - act as ranlib t - display contents of archive x[o] - extract file(s) from the archive command specific modifiers: [a] - put file(s) after [member-name] [b] - put file(s) before [member-name] (same as [i]) [D] - use zero for timestamps and uids/gids [U] - use actual timestamps and uids/gids (default) [N] - use instance [count] of name [f] - truncate inserted file names [P] - use full path names when matching [o] - preserve original dates [u] - only replace files that are newer than current archiv +e contents generic modifiers: [c] - do not warn if the library had to be created [s] - create an archive index (cf. ranlib) [S] - do not build a symbol table [T] - make a thin archive [v] - be verbose [V] - display the version number @<file> - read options from <file> --target=BFDNAME - specify the target object format as BFDNAME emulation options: No emulation specific options ar: supported targets: pe-x86-64 pei-x86-64 elf64-x86-64 elf64-l1om el +f64-k1om pe-i386 pei-i386 elf32-i386 elf64-little elf64-big elf32-lit +tle elf32-big srec symbolsrec verilog tekhex binary ihex dmake: Error code 129, while making 'Impl.a' dmake.exe: Error code 255, while making 'Impl\Impl.a' -> FAIL Installing Win32::ToolHelp failed. See C:\Users\Eurocom\.cpanm +\work\1430810127.6240\build.log for details. Retry with --force to fo +rce install it.
    Please could someone explain the problem for me.
    It is the first time I try to install a Win32 Module from CPAN with Strawberry Perl.
    Thanks for your help !!
What is this ? $^T
4 direct replies — Read more / Contribute
by Noloz
on May 05, 2015 at 03:37

    I recently started learning Perl. Looking at a script I have the following expression

    my $rand = $^T;

    and I do not know what $^T means or stands for. The code continues and it generates an R file open(Out1, >$rand".".R"); print Out1 "source('$Bin/varNumber2Rel.R')\n"; print Out1 "varNumber2Rel('".$options{'o'}.".varNumber'".", ".$options{'P0Cutoff'}.", ".$options{'p'}.")"; close(Out1); I hope you can help me! Thank you!
Print string next to pattern matching?
3 direct replies — Read more / Contribute
by sumathigokul
on May 05, 2015 at 02:29

    Hi all, i have a text file contains following lines...

    2 INT_NET Net : c_c 2 INT_NET Net : b_c 2 INT_NET Net : a_c
    Here, i want to extract string next to colon ':' i.e c_c, b_c and a_c and save them in another text file. How to print next to pattern matching?

    I also want your comments on my approach of this problem. I have two files, one is .vhd file (which contains nets names as a_c, b_c and c_c)and another is designer.log file which lists high fanout nets of the design. i have to extract these high fanout nets from designer.log file and accordingly i have to modify those nets in .vhd file. For this problem, i wrote perl script which extract high fanout nets with its corresponding statements also as shown above. From this statements i want to extract those nets name alone??

    Thank you all.

Perl script to find particular string and save those lines in another file?
3 direct replies — Read more / Contribute
by sumathigokul
on May 05, 2015 at 01:13

    Hi all, i want to search in a text file for '2' and copy the whole statement in another text file. Here is the code. It prints those matched statements and it also generated new.txt file, but the file is empty.

    use strict; my $find = "2"; open (FILE, "<high_fanout.txt") or die "could not open:$!"; my @line = <FILE>; for (@line) { if ($_ =~ /$find/) { print "$_\n"; print NEW "@line\n"; } } open (NEW, ">new.txt" ) or die "could not open:$!"; close (FILE); close (NEW);

    can anyone help me out from this mistake? Thank you all.

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
  • Outside of code tags, you may need to use entities for some characters:
            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 taking refuge in the Monastery: (8)
    As of 2015-05-06 11:20 GMT
    Find Nodes?
      Voting Booth?

      In my home, the TV remote control is ...

      Results (134 votes), past polls