Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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
Ceiling elements of an array!
3 direct replies — Read more / Contribute
by shadowman13
on May 06, 2015 at 04:20
    Hi All wisdom Monks,

    I'm new to Perl, so don't know if there is a way to ceil the number of elements inside an array?

    I got a task like below:

    +Get a list of modules if number of modules is 8 ceiling(6/2)= ceiling(3)=3 -> call the first 3 modules on port 80 and call the last 3 modules on port 8080

    +if there is 5 modules deployed -> ceiling(5/2)= ceiling(2.5)=3 -> call the first 3 modules on port 80 and call the last 3 modules on port 8080 (the module “in the middle” will be called twice)

    Could you help me with an algorithm or a way to do this in perl?
Perl pattern matching question
3 direct replies — Read more / Contribute
by MadhAric
on May 06, 2015 at 04:12
    I have a sentence. My task is to find out whether the articles A and An are properly used. if a followed by a vowel , replace it with an (like replace a apple with an apple) and vice versa replace an dog with a dog. can you please tell me the code I am with basic level of PERL and wrote the following piece which did not give the desired result $string =~ (s/a (a|e|i|o|u)/an /g); print "\n$string\n"; Do we need to use loops and sub strings for this
Find maximum number in text file and copying its full statement in new text file?
3 direct replies — Read more / Contribute
by sumathigokul
on May 05, 2015 at 23:02

    Hi all,

    i have a text file that contains the following lines

    High fanout nets in the post compile netlist: Fanout Type Name -------------------------- 2 INT_NET Net : c_c Driver: c_pad 2 INT_NET Net : b_c Driver: b_pad 2 INT_NET Net : a_c Driver: a_pad 1 INT_NET Net : sum_c Driver: sum_1_SUM0_0 1 INT_NET Net : N_5 Driver: sum_1_CO0_i

    I have to write a perl script that saves the following statements only, i.e. high fanout nets alone. For that, if i write a script which find maximum number in my text file and copies those statements in new file, it will copy the following statements.

    2 INT_NET Net : c_c 2 INT_NET Net : b_c 2 INT_NET Net : a_c

    Here is the code i tried, but could not get the text file as i wish....

    my $high_number = 0; open (F1, "<new.txt") or die "cant open it$!"; while (<F1>) { my ($number) = m/:(\d+):/; $high_number = $number if $number > $high_number; } print "Highest number found = $high_number\n"; close (F1);

    please help me out in this, thank you all....

load a file in memory and extract parts
4 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.to=me\@me.com log4perl.appender.Email.from=me\@me.com log4perl.appender.Email.smtp=smtp.me.com 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
2 direct replies — 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
    OUTPUT
    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="http://www.w3.org/TR/REC-xml"> <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>
SSL ERROR
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 => "https://url.com"); $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

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!
  • 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?
    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 making s'mores by the fire in the courtyard of the Monastery: (9)
    As of 2015-05-06 10:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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









      Results (134 votes), past polls