Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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
Problem installing TK module
2 direct replies — Read more / Contribute
by dgriff792
on Mar 31, 2015 at 17:33
    I have Strawberry Perl installed and trying to run dmake and getting many errors. This is the latest error. collect2.exe: error: ld returned 1 exit status dmake.exe: Error code 129, while making 'blib\arch\auto\Tk\Tk.xs.dll' Can someone tell me how to fix this? Thanks!
strange form in sub parameters
2 direct replies — Read more / Contribute
by grasshopper!!!
on Mar 31, 2015 at 17:01

    Can anyone explain why a subroutine in perl cookbook section 7.23 has the form

    sub sysreadline(*;$) {
    in its parameters what is *;$ is it a special glob. thank you

Need help parsing email using MIME::Parser
1 direct reply — Read more / Contribute
by gossamer
on Mar 31, 2015 at 15:41
    Hi, I'm trying to parse information out of the body of what I believe is a base64 encoded email:
    Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64
    I'm mostly a perl novice. I'm trying to use MIME::Parser, which I believe is the best module for doing this. I've read practically every google response on how to use this module that exists, and still don't understand how to get the decoded version of the body.

    The decoded message is written to disk by default, but I don't understand how to store the decoded body in an array so I can manipulate it.

    http://www.perlmonks.org/bare/?node_id=188084

    I've even followed this extensive example, and it also doesn't appear to decode the body.

    A short, simple example would be most appreciated.

    I've written the following bit of code, but it doesn't appear to go into the for-loop:

    #!/usr/bin/perl -w use strict; use MIME::Parser; my $tmp_dir = '/tmp/parser-dir'; my $parser = MIME::Parser->new; mkpath($tmp_dir) unless -d $tmp_dir; $parser = MIME::Parser->new( ); $parser->extract_uuencode(1); $parser->extract_nested_messages(1); my $entry = $parser->parse(\*STDIN); for my $part ($entry->parts) { # dig into the parts if($part->mime_type eq 'multipart/alternative') { for my $a ($part->parts) { if($a->mime_type eq 'text/plain') { $part = $a; last; } } } my $mime = $part->mime_type; if($mime =~ m'text/.+' && !$found_msg++) { my $fh = $part->open('r'); if($fh) { while(defined(my $line = $fh->getline)) { $line =~ s/[\r\n]//g; push(@message, $line); } $fh->close; } } }
Make use of a java object in Perl
4 direct replies — Read more / Contribute
by ravin_perl
on Mar 31, 2015 at 15:18
    Scenario : there is a java class as given below :
    public class TestSelenium { public void googleTest() throws Exception { WebDriver driver = new InternetExplorerDriver(); driver.get("http://www.google.com/webhp?complete=1&hl=en"); } }
    There is a perl program which makes use of Inline::Java module to call the googleTest of java class written above. Perl program looks like.
    use warnings; use Selenium::Remote::Driver; use Inline Java => 'STUDY', CLASSPATH => 'C:\selenium\selenium-java-2.37.0\selenium-2.37.0\libs\se +lenium-java-2.37.0.jar;C:\selenium\SeleniumTestPoc\bin\MyJar.jar;C:\s +elenium\selenium-java-2.37.0\selenium-2.37.0\libs\selenium-server-sta +ndalone-2.37.0.jar', STUDY => ['TestSelenium']; $test= TestSelenium->new; $test->googleTest;
    Now the above Perl code will open IExplorer and go to google.com page. In my Perl program further to $test->googleTest; I want to make use of same browser that was opened by java(WebDriver driver = new InternetExplorerDriver();) and perform a search for text "Cheese".

    Question is, can the object of WebDriver class("driver" in this case) be further used in my Perl program so that I can use same browser and perform different UI operations on it in Perl?

Perl linked list
4 direct replies — Read more / Contribute
by Perl_is_Perl
on Mar 31, 2015 at 08:39
    Dose anyone know how to count nodes numbers in a linked list or could anyone tell me which book should I start with to learn about linked list? Thanks a lot ! The question is from codility.com, which I use it to evaluate my coding ability recently. Due to the copyright problem, I need to remove it from here, My bad ! please check the original qestion below:

    https://codility.com/honeypot/Perl_is_Perls-Perl-test-1 Here comes the codes I come up with, thanks for all your explanation of linked list data structure :

    sub solution

    {

    my ($L)=@_;

    my $count=1;

    while($L=$L->{'next'})

    {

    $count++;

    last if $L->{'value'} eq 'undef';

    }

    return $count;

    }

When call_argv() actualy executes function
2 direct replies — Read more / Contribute
by DrMoisha
on Mar 31, 2015 at 08:29
    Dear Monks!

    I'm now trying to call perl functions from c code. I've already built perl with MSVS2013 Professional on Windows 7 64 bit. I'm now testing perlembed code, and I've run into problem.

    Let's look at Calling a Perl subroutine from your C program.

    #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *args[] = { NULL }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /*** skipping perl_run() ***/ call_argv("showtime", G_DISCARD | G_NOARGS, args); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
    My trouble is if I call some sub, it only actually executes on perl_destruct(my_perl);. I did not found what causes such behaviour in perlembed. And I don't quite understand what is happening, so I tried place perl_run(my_perl), or GL_EVAL in different places.

    Okay,- I've thought,- let's try Maintaining a persistent interpreter example. I don't want to bloat my question so here is link Maintaining-a-persistent-interpreter-example
    This example crashes here:

    if(SvTRUE(ERRSV)) fprintf(stderr, "eval error: %s\n", SvPV_nolen(ERRSV));
    When I comment this out, it still does nothing, even on perl_destruct();

    So my first question: is there any manual for me to understand, what happens when call_argv() is called? I'm now reading perlguts, perlcall, however, I cannot find it. If you can, please specify me right way.:)

    And second question: when call_argv(); actually executes function? Or can I force somehow to do it? Thank you!


    EDIT
    Okay, function is called with call_argv(). It is problem with output. Print in function, does not show up until perl_destruct()
    /EDIT
Net::Server blocks on non-blocking socket with SSL
1 direct reply — Read more / Contribute
by cavac
on Mar 31, 2015 at 07:36

    I'm using Net::Server for a lot of stuff, including my own Websocket implementation. For this, i switch the socket to non-blocking like this:

    my $webflags = 0; fcntl(STDIN, F_GETFL, $webflags) or die "Couldn't get flags for HANDLE : $!\n"; $webflags |= O_NONBLOCK; fcntl(STDIN, F_SETFL, $webflags) or die "Couldn't set flags for HANDLE: $!\n";

    Then i do bytewise reads like this:

    my $data = ''; my $buf; while(1) { eval { my $status = sysread(STDIN, $buf, 1); }; last if(!length($buf)); $data .= $buf; $buf = undef; }

    Works quite nicely, and yes, i'm aware that this isn't the most efficient way to do it. But it is nice and debugable.

    The problem is: When SSL is active, sysread() blocks, but it shouldn't.

    For SSL i use something like this (and yes, it works for most use cases, since i'm only using non-blocking sockets in websockets):

    $server->run( [...some other stuff...] proto => 'ssl', usessl=>1, SSL_key_file=> $config->{server}->{sslkey}, SSL_cert_file=> $config->{server}->{sslcert}, [...some other stuff...] );

    What am i doing wrong?

    "For me, programming in Perl is like my cooking. The result may not always taste nice, but it's quick, painless and it get's food on the table."
Acce sing single element without args
1 direct reply — Read more / Contribute
by Anonymous Monk
on Mar 30, 2015 at 22:56

    to be more precise. Here is the code of a sub

    sub interface_control { my $s = shift; my (@r, $v, @h); $s->get_handles(rtrs=>\@r, vars=>\$v, hosts=>\@h);

    get_handles returns the handle for the args specified. These args are stored as hash/key pair in a file

    Call to the sub is made via interface_control($s)

    MY question is , i want to specifically access, one of the element in the array @r, say only $r[0]. Is there a way to access this or pass any reference to interface_control call

Controlling input and output of different program
2 direct replies — Read more / Contribute
by rkrasowski
on Mar 30, 2015 at 18:10
    Hi Monks, again, seems like simple problem but I can't solve this. I would like to control one program (that is normally controlled from terminal) with perl program. So , I understand there are few ways of managing it. I started with reading output of the program using pipes and I can not do it. Here is an example of what I am talking about:
    # open my $READ, "-|", "./dialog.pl"; while (<$READ>) { print $_; } close $READ;
    Here is the dialog.pl program that I am trying to interact with:
    print "How old are you? "; my $age = <>; print "You are $age.";
    The way I understand first program will open dialog.pl program and display "How old are you?" in the terminal,but it is not the case. What is the issue here? I would like to catch output from dialog.pl , and respond to it. I also understand that I will have to fork the program to be able to do writing and reading from dialog.pl at the same time. Thanks like always. Robert
Replace bits
1 direct reply — Read more / Contribute
by newbiecali
on Mar 30, 2015 at 17:35
    Hi

    i am newbie to Perl and need to learn from starting
    i have very big file of data (3Gb)like below


    00101100
    00101101
    11H00101
    HHHHHHHH
    01011001
    LLLLLLLL
    1011010L
    0110111L
    00000000
    00111111


    i need to replace H to 1 in column3 and L to 0 in column 8
    only so the file looks like below

    00101100
    00101101
    11100101
    HHHHHHHH
    01011001
    LLLLLLL0
    10110100
    01101110
    00000000
    00111111


    can it take text file "file1.txt"
    and spit out the output in "output.txt"
    something like that

    i will appreciate any help

    Thanks


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 about the Monastery: (9)
    As of 2015-03-31 22:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:









      Results (673 votes), past polls