Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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
Loop walkthrough
2 direct replies — Read more / Contribute
by beanscake
on Jul 21, 2014 at 01:06

    Hi Monks,
    In an interview to be processed by any of the available staff , namely patrick or Juliet ,to interview two job applicant namely , James and John .
    Begins: if James or John graduated from college with grade A then, employ. One , my default choice is James , but if James did not then employ john. If both has grade A then go for john, no job for them if none of them graduated with grade A ..... This is my scenario Please perl monks help me with infinite loop for this scenario..

Is it possible to write to STDIN ?
4 direct replies — Read more / Contribute
by exilepanda
on Jul 21, 2014 at 00:56
    I am trying to provide a simulation on Web request, GET and POST, during my shell development, coz I don't want to implement a batch form query combination and see the results via my browser. This is very inefficient if I use my browser to fill in the blanks, change something and submit again time to time.

    My simulation module is simply to set $ENV{REQUEST_METHOD} = "GET" and then $ENV{QUERY_STRING} = "Var1=Val1&Var2=Val2" (when I run the code in shell) Now the GET request is done, but the POST request won't work as it read (STDIN, my $buf, 4096) and I can't find anyway to feed the STDIN

    My recent shortcoming approach it to alter a POST request to GET and URI encode the data string, it works on some cases, however it won't pass through when somecgi.pl performs :

    if ( $ENV{REQUEST_METHOD} eq "GET" ) { print_the_form(); } elsif ( $ENV{REQUEST_METHOD} eq "POST" ) { handle_the_form(); } else { print "GET and POST request only" }
    Any clues for this ? Thanks a lot!
Bizarre Dancer encoding behavior
3 direct replies — Read more / Contribute
by xyzzy
on Jul 20, 2014 at 21:25

    Short version: When using return to send a response, Dancer converts a Unicode string into ISO8859-1. When setting the content directly via the Dancer::Response->new() method, the response contains the correct string.

    Long version: I have an extremely minimal Dancer app. At some point, I was going to expand it to do a lot more, but as of right now the only thing it does is return the currently-playing track of an MPD server running on the same machine. A static page with an HTML5 internet radio player sends a request and updates a "Now Playing:" span at regular intervals. I needed something quick and dirty without mucking about with the two MPD modules on CPAN, so I used a system call. For those unfamiliar with MPD, it is a music player with a server-client architecture. There are a plethora of clients available for all different platforms, but the most basic is a CLI client called mpc. Called with no arguments, it returns the server status:

    xyzzy@asscat:~$ mpc
    ДДТ - Чёрно-белые танцы
    [playing] #27/31 1:21/6:03 (21%)
    volume: n/a repeat: off random: off single: off consume: off
    xyzzy@asscat:~$

    Here's the first version:

    get '/np' => sub { return `mpd | head -n1`; }

    Simple enough. But instead of the Unicode, my span looks like this:

    Now playing: ””Т - Ч‘€но-бел‹е ‚а톋

    I spent an hour trying to enable utf8, checking the HTTP headers, the meta tags on the page, even using Encode, but nothing worked. Then I rewrote my handler like so:

    get '/np' => sub { Dancer::Response->new( status => 200, content => `mpd | head -n1`, ); }

    Suddenly:

    Now playing: ДДТ - Чёрно-белые танцы

    Most of me only cares that it works now. But part of me is still baffled why one way works and the other way doesn't. What is it about return that mangles the sting encoding? It has to be something inherent in Dancer, because if I do

    xyzzy@asscat:~$ perl -e'sub a {return `mpc|head -n1`}print a'
    ДДТ - Герой

    it works perfectly fine. Does anyone here know enough about Dancer's internals or is clever enough to figure this out?


    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.
API Calls with RESTful & Trello
2 direct replies — Read more / Contribute
by humbleCoder
on Jul 20, 2014 at 18:41

    I am writing a script and I am trying to write a file from a url that is in the form of a .json. I need to basically get the file from a url to my home directory on a linux server. I am getting this json from WWW.trello.com. I am trying to get the whole board to export as a .json. The site uses RESTful api and I don't know how to get the file from a url, then write the information it displays to a file.

Perl vs Angular-Node
4 direct replies — Read more / Contribute
by james.hans
on Jul 20, 2014 at 13:08
    Folks, I am trying to convince my company on using Perl vs the JavaScript framework. I am leaning on Perl (since I have been using it for a while). However I do not know how Perl scales when it comes to handling thousands of hits per hour. I am not even sure what kind of stack/tools need to be in place for that to happen as far as perl is concerned. So far i have only used Perl on simple Perl-MysQL (or MSSQL) projects that had to handle a few hundred to little less than 2000 hits per hour. Is it safe to assume that Perl (or PHP) is suitable only as far as handling few hundred requests are concerned. Anything more requires JSP or Node stacks ?
Win32 GUI onDrag?
2 direct replies — Read more / Contribute
by AndreaN
on Jul 20, 2014 at 11:26

    Hello,

    I'm currently creating an application in which I use the onDropFiles event of Win32::GUI.

    I wanted the icon of the button to change when the user is dragging the file on it. I looked in the documentation but I didn't find any event like a "onDraggedFile" or anything similar. Has anybody found this problem? Did I miss something or is it just impossible to change icon in this way using Win32::Gui?

    Thanks!

How to Read file from remote machine?
2 direct replies — Read more / Contribute
by dilip.patel
on Jul 20, 2014 at 04:52

    I am new to this group, so sorry in advance if I make any mistake. I am using perl from last one year. I want to read file varying size(1mb to 300mb ) from remote machine which having password and simultaneously want to perform operation . I tried File::Remote to read file but it dose not support host having password.

    Thanks in advance for your help.

no visibility to global hashref ?!?
5 direct replies — Read more / Contribute
by kerchunk
on Jul 20, 2014 at 01:50

    Somebody must've surreptiously removed the caffeine from my caffeinated beverage because I just can't see why this doesn't work.

    I simply wish to pass the hard-coded source hashref and a target hashref to a sub to measure lengths of strings from the first and populate the second. That part works great.

    But I don't seem to have any visibility of the target hashref outside of measureHashrefLength even though it's declared in my main sub.

    O Monks of Perl, enlighten me!

    #! /home/gnu/bin/perl package main; use strict; use autouse 'Data::Dumper' => qw(Dumper); # prototypes sub readAdvisorTablesIntoHashref($); sub measureFieldLengths(); sub writeOutHashrefs(); sub writeOutHashref($$); #globals my $allActivity_hashref = { '1234-5678' => { 'Address' => "656 Poplar" ,'City' => "Monroe" ,'State' => "WI" ,'Zip' => "87654" ,'Phone' => "444-555-666 +6" } , '5757-4968' => { 'Address' => "656 Poplar" ,'City' => "Nightmare" ,'State' => "ND" ,'Zip' => "56532" ,'Phone' => "777-8888" } }; my $allActivity_fieldLength_hashref = undef; my $subHadErrors = 0; $subHadErrors = measureFieldLengths() unless( $subHadErrors); $subHadErrors = writeOutHashrefs() unless( $subHadErrors); exit(0); #------------------------------- sub measureFieldLengths() { print "entering measureFieldLengths\n"; my $errorHit = 0; measureFieldLength( "ACTIVITY", $allActivity_hashref, $allActivity_f +ieldLength_hashref); print "exiting measureFieldLengths\n"; return $errorHit; } #------------------------------- sub measureFieldLength($$$) { my ( $tableName, $tableName_hashref, $tableName_fieldLength_hashref) + = @_; print "entering measureFieldLength\n"; my $errorHit = 0; print "--inside measureFieldLength--input --". Dumper( $tableName_h +ashref); unless( $errorHit) { for my $Id ( sort{ $tableName_hashref->{$a} <=> $tableName_hashref->{$ +b} } keys( %$tableName_hashref)) { my $row_hashref = $tableName_hashref->{$Id}; for my $field_name ( sort{ $row_hashref->{$a} <=> $row_hashref->{$b} } keys( %$row_hashref)) { my $field_valu = $row_hashref->{$field_name}; $tableName_fieldLength_hashref->{$Id}->{$field_name} = 0; $tableName_fieldLength_hashref->{$Id}->{$field_name} = length( + $field_valu) if( defined( $row_hashref->{$field_name})); } } } print "--inside measureFieldLength--output --". Dumper( $tableName_f +ieldLength_hashref); print "exiting measureFieldLength\n"; return $errorHit; } #------------------------------- sub writeOutHashrefs() { print "entering writeOutHashrefs\n"; my $errorHit = 0; print "--inside writeOutHashrefs --input --". Dumper( $allActivity +_fieldLength_hashref); print "WT* why isnt global allActivity_fieldLength_populated ???? +\n"; writeOutHashref( "ACTIVITY", $allActivity_fieldLength_hashref); print "entering writeOutHashrefs\n"; return $errorHit; } #------------------------------- sub writeOutHashref($$) { my ( $tableName, $tableName_hashref) = @_; print "entering writeOutHashref\n"; my $errorHit = 0; unless( $errorHit) { for my $Id ( sort{ $tableName_hashref->{$a} <=> $tableName_hashref->{$ +b} } keys( %$tableName_hashref)) { my $row_hashref = $tableName_hashref->{$Id}; print $Id."\n"; my $outline = $Id; for my $field_name ( sort{ $row_hashref->{$a} <=> $row_hashref->{$b} } keys( %$row_hashref)) { my $field_valu = $row_hashref->{$field_name}; $outline = $outline.join('=', $field_name, $field_valu); } print $outline."\n"; } } print "entering writeOutHashref\n"; return $errorHit; }
POST in WWW::Mechanize::PhantomJS
2 direct replies — Read more / Contribute
by pghilb
on Jul 19, 2014 at 21:18

    Some years ago, I used to work with WWW::Mechanize, where you POST'ed something via a call like

    $mech->post($url, \%data2post);

    Today I started to study WWW::Mechanize::PhantomJS (kind of the hottest thing nowadays), and it turned out that the old-style calls (as above) no longer work, producing an error with HTTP::Request::Common.

    Naturally, neither there are books/manuals on this new module, nor, sadly, any comprehensive examples on the Web to be found on the matter. Would greatly appreciate some experience on POST in the module shared.

Problem using Gmail Send
4 direct replies — Read more / Contribute
by IvanH
on Jul 19, 2014 at 18:36
    Hi Monks,

    I have some, but limited, experience with PERL. I am trying use Email::Send::SMTP::Gmail to send emails. I tried using the sample code provided with the module but can't get it to work. My OS is Windows 8.1, 64 bit. Here is the code I used (but with my real password:

    use strict; use warnings; use Email::Send::SMTP::Gmail; my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com', -login=>'IHipschman@gmail.com' +, -pass=>'mypassword'); $mail->send(-to=>'IHipschman@yahoo.com', -subject=>'Hello!', -body=>'Just testing it<br>Bye!',-contenttype=>'text/html' +); $mail->bye;

    The response I receive is:

    C:\Users\Ivan\Documents\BSA\EMAIL\GmailSend>perl tryitmodified.pl Could not connect to SMTP server Can't call method "send" without a package or object reference at tryi +tmodified. pl line 8.
    .

    Can anyone suggest what the problem is? I have tried running from an administrator level command prompt and turning off the Windows firewall.

    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 musing on the Monastery: (9)
    As of 2014-07-23 05:48 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (133 votes), past polls