Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
Including modules and pragmas in caller's scope via use
2 direct replies — Read more / Contribute
by wanna_code_perl
on Jul 29, 2014 at 16:49

    Hello monks,

    I already have several Local::... modules that do things too specific for general public consumption. Now I have a "smaller" problem:

    Like many programmers, I have an ever-growing repository of useful subroutines that are either too isolated or too simple to (yet...) merit their own module (in the Local:: module namespace or otherwise). I also have a list of modules and pragmas I use in almost every script. However, these are things I'd like to have available in most of my internal-use scripts.

    The subroutines? Easy. Just pile them in a new module (say, Local::Junk and @EXPORT them by default (or with Exporter::Easy and qw(:all) if I'm feeling extra pedantic...).

    But I don't know how to the other modules (and pragmas) that I'd like to include by default whenever I use Local::Junk, such as List::Util, autodie, etc.

    In other words, I'd like to be able to simply do something like this:

    use Local::Junk qw(:all);

    Instead of:

    use strict; use warnings; use autodie; use List::Util qw(first max maxstr min minstr reduce shuffle sum); # etc...
LWP::UserAgent error Unexpected keys - LocalHost
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 29, 2014 at 16:22
    Hi All

    I tried to grab a page using this code on my Mint10 PC. For some reason it chokes. I tried the same on another Mint17 PC connected through the same network and it worked. But I don't understand what the error is trying to tell me. Any suggestions? I was able to get python to get the same page on the Mint10 PC too using python's urilib.

    Here's the code

    use LWP::UserAgent; use HTTP::Request::Common qw(GET); use HTTP::Cookies; my $ua = LWP::UserAgent->new; # Define user agent type $ua->agent('Mozilla/8.0'); # Cookies $ua->cookie_jar( HTTP::Cookies->new( file => 'mycookies.txt', autosave => 1 ) ); # Request object my $req = GET 'http://www.perlmeme.org'; # Make the request my $res = $ua->request($req) || die "Bad Get"; # Check the response if ($res->is_success) { print $res->content; } else { print ">> ",$res->status_line . "\n"; }

    here's the response

    try_web_get.pl >> 500 Unexpected keys - LocalHost

    Thanks to anyone who may help

using the feature 'switch' in loops
3 direct replies — Read more / Contribute
by martell
on Jul 29, 2014 at 15:13

    Hi Monks

    I was wondering for thoughts from you about the new 'switch' feature in combination with loop control statements like 'last' and 'next'.

    When I first used the 'switch' statement, within a loop, I was suprised by the behaviour when used in combination with the last statement. Without prior thought I programmed:

    use feature "switch"; foreach $a (1..2) { for ($a) { when (1) {print "1\n"; last;} when (2) {print "2\n"; last;} } }

    This prints:

    1 2

    instead what I expected (in my case, the 'when' blocks are containing loop termination conditions I wanted to check before doing some work in the foreach block):

    1

    The code is easily adapted for my intention:

    use feature "switch"; LOOP: foreach $a (1..2) { for ($a) { when (1) {print "1\n"; last LOOP;} when (2) {print "2\n"; last LOOP;} } }

    I was wondering if this behaviour was also for other monks puzzling. I didn't expected that the 'last' statement in the switch statements controlled the flow within the switch statement. It easily solved of course and clearly mentionned in the docs. My fault for not reading them throughly.

    But did you expected this behaviour when you used this feature for the first time?

    Kind regards

    Martell

Naming a module that handles SIP2
3 direct replies — Read more / Contribute
by gmcharlt
on Jul 29, 2014 at 12:39

    I'm one of the folks who hacks on a set if modules that handles a protocol used by libraries called SIP2 (not to be confused with the telephony protocol). The modules uses Net::Server.

    Currently, the modules are used by one project, and a fork of them are included in another. We're planning on folding the fork back in and making the modules suitable for submission for CPAN. One issue: the modules names, "ILS" and "Sip", are clearly unsuitable.

    I'd like advice on what to rename the module to. Net::SIP2::Server? Net::3MSIP2::Server? (The "3M" bit comes from the name of the company that started the protocol). Library::Net::SIP2?

    If you're curious, the code can be found here:

    http://git.evergreen-ils.org/?p=working/SIPServer.git;a=summary

IO::Socket::SSL & Net::Websocket::Server Question
2 direct replies — Read more / Contribute
by huchister
on Jul 29, 2014 at 10:37
    Greeting monks,

    I have minor question regard with IO::Socket::SSL issue.

    I am working on building Net WebSocket Application using Net::WebSocket::Server module.

    http://search.cpan.org/~topaz/Net-WebSocket-Server-0.001003/lib/Net/WebSocket/Server.pm

    I was successfully building websocket server, but little concern about building IO::Socket::SSL objects.

    It seems everytime when handshake occurs, its building new IO::Socket::SSL object for clients with new Symbol creation. When I dump socket object variable in log file it output as follows:

    $VAR1 = bless( \*Symbol::GEN67, 'IO::Socket::SSL' );

    My concern is this GEN # number is keep increasing (ex. Symbol::GEN68, Symbol::GEN69, Symbol::GEN70 .... so forth) no matter what. I don't know whether this Symbol::GEN object should be deleted or not.

    I wonder if anybody can enlighten me in some aspect of using IO::Socket::SSL. What would be proper way to close / shutdown its service. Does it closes automatically if socket isn't being used? Should I concern about symbol # increases?

    For your record, I am using Steffen Ullrich's version of IO::Socket::SSL

    http://search.cpan.org/dist/IO-Socket-SSL/lib/IO/Socket/SSL.pod<br><br> Thanks!
Populate an HTML template and save as a new HTML file
1 direct reply — Read more / Contribute
by pansywhacker
on Jul 29, 2014 at 07:11
    Hi guys!

    I'm currently using Perl Dancer and TT2 to make a application in the browser.

    I have a program which loops through a larger array and splits it into smaller ones - I would like each of these smaller arrays to populate an HTML template(which file being conditional on the size of the parameter array), I would then like the populated HTML template to be saved to a file for retrieval later on.

    Is there anything that can do such a task?

How to sort in perl on the basis of one field.
5 direct replies — Read more / Contribute
by Ankur_kuls
on Jul 29, 2014 at 01:22

    Hi All, I have the below data as the elements of an array (lets say @array).

    field1,fieldA,fileda (1st element) field2,fieldB,filedb (2nd element & on) field3,fieldC,filedc

    where all fields are numeric values. now I need to join these elements in one scalar value ($all_data) but only after they are sorted in descending order on the basis of second field (ie fieldA, fieldB). Any one pls could help me in this...Pls let me knoe if you need more info. on that...thanks a lot

Using Perl to automate GDB
4 direct replies — Read more / Contribute
by eloc
on Jul 28, 2014 at 19:46
    Monks, I humbly come before seeking your great wisdom. I essentially want to use Perl to send input commands to GDB, read the output GDB supplies from these commands, and based on that output send more commands to GDB. I believe open2() or open3() may be of use to me. Is this possible? If so could you show me a simple example? However, I am new to Perl, and would deeply appreciate any examples or advice you can provide.
Error with Net::SSLeay
2 direct replies — Read more / Contribute
by grektokomus
on Jul 28, 2014 at 16:38

    Hello Monks,

    I'm working on a simple script to retrieve JSON from an HTTPS web service. The code is being developed on a Windows 2008 server with Active Perl. The script reports an error on compilation, but then successfully retrieves the desired JSON from the Server. I've put substantial effort into eliminating the error and now seek assistance. Here is the declaration and the error:

    #!/usr/bin/perl -w use strict; #use diagnostics; use JSON -support_by_pp; use LWP 6.04; use LWP::UserAgent; use LWP::Protocol::https; use Net::SSLeay 1.63; use IO::Socket::SSL 1.997;
    Use of uninitialized value in subroutine entry at blib\lib\Net\SSLeay.pm (autosplit into blib\lib\auto\Net\SSLeay\randomize.al) line 912.

    Based on a few similar problems found on the internet, I have verified my LWP modules. I have updated to the latest SSLeay Module (which required force install with ppm). I have also installed OpenSSL 1.0.1h from slproweb.com (although when I verify using https://gist.github.com/dolmen/10096474, it confirms 1.0.1g) .

    I would greatly appreciate guidance to resolve this issue.

Spreadsheet::WriteExcel how to maintain row number
2 direct replies — Read more / Contribute
by terrykhatri
on Jul 28, 2014 at 16:14
    My apologies !!

    Original content (below) and title restored by GrandFather.

    Hi,

    First here is the related snippet of code I want to ask your assistance for :

    my $row=1; while ($a = $sth->fetchrow_hashref()) { $worksheet->write_url($row,0, qq({internal:'$a->{OrderID}'!A1})); $worksheet->write($row,0, $a->{OrderID}, $bold); $worksheet->write($row,1, $a->{OrderDate}); $worksheet->write($row,2, $a->{ShippedDate}); $worksheet->write($row,3, $a->{CustomerName}); $worksheet->write($row,4, $a->{ShipVia}); $worksheet->write($row,5, $a->{ShipName}); $worksheet->write($row,6, $a->{ShipAddress}); $worksheet->write($row,7, $a->{ShipCity}); $worksheet->write($row,8, $a->{ShipRegion}); $worksheet->write($row,9, $a->{ShipPostalCode}); $worksheet->write($row,10, $a->{ShipCountry}); $worksheet->write($row,11, $a->{Freight},$number); $freight = $a->{Freight}; $ordttl = $a->{'Total'} + $a->{'Freight'}; $worksheet->write($row,12,$ordttl,$number); $row++; print "Current row number is $row\n";

    After $row++ loop how do I maintain the current $row number so I can add other stuff like grand total to be positioned just after $row++ loop in the same worksheet.

    As you can see above I am printing the current $row after $row++ loop and it shows that current row is 2 this is not I want, I want the next row after $row++ loop, I hope I have made my question clear enough.

    Many many thanks for your help !!

    Terry

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 browsing the Monastery: (6)
    As of 2014-07-30 00:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (229 votes), past polls