Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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
load a file in memory and extract parts
3 direct replies — Read more / Contribute
by healingtao
on May 05, 2015 at 16:56

    Hi Monks, I have a csv file which has about 100mb 60k rows and has 10 columns.The first 2 colmns are the key. I need to load it into memory and based on keys passed in externally find the matched row and extract some data to do some calculations. The external input will come in with about 5k keys. I'm curious what is the most efficient method for getting this done? Thanks in advance

Change email config for Log::Dispatch::Email::MailSender
1 direct reply — Read more / Contribute
by tonytronics
on May 05, 2015 at 15:20
    Greetings Elders

    I have switched my loggin to use Log::Log4perl and Im having a hard time using Log::Dispatch::Email::MailSender for emailing logs. The code snippet below is my working example.

    use Log::Log4perl qw(get_logger :levels); my $log4perl_conf=<<CFG log4perl.rootLogger=INFO, Email log4perl.appender.Email=Log::Dispatch::Email::MailSender\ log4perl.appender.Email.from=me\ log4perl.appender.Email.min_level=info log4perl.appender.Email.layout=Log::Log4perl::Layout::PatternLayout log4perl.appender.Email.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:s +s} [%F{1}:%c{1}] %5p> %m%n CFG ; Log::Log4perl::init(\$log4perl_conf); my $logger = Log::Log4perl->get_logger(); $logger->info('The first message bla bla'); $logger->info('The second message bla bla'); some_func(); sub some_func { my $logger = Log::Log4perl->get_logger(); $logger->info("some_func was called"); }

    Here are my questions

    1. why does the logger not send emails unless I add get a logger locally by adding my $logger = Log::Log4perl->get_logger(); to some_func Im not sure why it cant use the global version
    2. How do I get access to the logger configuration so I can change the email subject during execution say to indicate success or failure. I basically want to change things like subject or to address dynamically in my script

    As a workaround for Q2 above in my main program I now use Log::Log4perl::Appender::String to store the message and then ues send an email at the end of my script using MIME::Lite. I would prefer to have this all handled by the logger. Thanks

plack: close filehandle responsibility
1 direct reply — Read more / Contribute
by basiliscos
on May 05, 2015 at 13:21

    Hello dear monks!

    I'm using Kelp, which is very Plack-centered framework.

    I have the following code for rendering icons:

    use Path::Tiny; ... my $image = path($self->config('storage'), $domain_id, "icon-${size}.i +co"); ... return $self->res->set_content_type('image/x-icon') ->render_binary($image->filehandle('<', ':raw'));

    After some time of execution under plackup I got the following error:

    Error open (<:raw) on \'storage/3/icon-256.ico\': Too many open files at ...

    Why so? I looked at Kelp::Request sources, and it just transfers the filehandle for Plack. Why Plack does not closes it after rendering the requests?

    Yes, I know that I could do something like:

    return $self->res->set_content_type('image/x-icon') ->render_binary($image->slurp);

    but this is counter-effective a little bit? sendfile(2) cannot be used by server, and why at all I should load the whole image into perl, while actually i don't need it?

    WBR, basiliscos.
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 !!

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 perusing the Monastery: (5)
    As of 2015-05-05 22:37 GMT
    Find Nodes?
      Voting Booth?

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

      Results (127 votes), past polls