Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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
How to check the request is (GET OR POST) in CGI
2 direct replies — Read more / Contribute
by kanewilliam7777
on Sep 24, 2018 at 08:34

    I have used CGI method

    Please let me know how to check request the value (GET OR POST) in CGI

[OT] Folding Perl code with Emacs 25
2 direct replies — Read more / Contribute
by loris
on Sep 24, 2018 at 04:45

    Hi,

    To get folding in Emacs 25 for Perl programs I have cargo-cult-copied the outline-based set-up https://github.com/villadora/emacs-config/blob/master/modes.el.

    In particular I have:

    ;; CPerl mode hook (setq cperl-mode-hook 'my-cperl-customizations) (defun my-cperl-customizations () "cperl-mode customizations that must be done after cperl-mode load +s" (outline-minor-mode) (abbrev-mode) (defun cperl-outline-level () (looking-at outline-regexp) (let ((match (match-string 1))) (cond ((eq match "=head1" ) 1) ((eq match "package") 2) ((eq match "=head2" ) 3) ((eq match "=item" ) 4) ((eq match "sub" ) 5) (t 7) ))) (setq cperl-outline-regexp my-cperl-outline-regexp) (setq outline-regexp cperl-outline-regexp) (setq outline-level 'cperl-outline-level) )

    My expectation was that if I have

    =head2 STUFF =over =item foo Do foo =cut sub foo { return 'foo'; }

    I should be able to fold to

    =head2 STUFF...

    but instead I just can only fold to, say

    =head2 STUFF... =item foo Do foo =cut sub foo { return 'foo'; }

    i.e. the hierarchy, which I thought gets defined by 'outline-level' doesn't seem to work.

    I do have

    (add-hook 'outline-minor-mode-hook 'outshine-hook-function)

    to get tab-cycling, but maybe this is screwing things up.

    Any thoughts or other approaches?

    Thanks,

    loris

    Note: This is something I originally posted, somewhat spuriously, to the Orgmode mailing list several weeks ago. Not that surprisingly, I got no reply.

LWP vs ExtUtils::Installed vs libwww::perl vs Module::Metadata
3 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 23, 2018 at 02:56
    perl -MExtUtils::Installed -le 'print join "\n", grep /lwp/i, ExtUtils::Installed->modules()'
    
    LWP::ConsoleLogger
    LWP::MediaTypes
    LWP::Protocol::http::SocketUnixAlt
    LWP::Protocol::https
    Test::LWP::UserAgent
    
    perl -MExtUtils::Installed -le 'print join "\n", grep /libwww/i, ExtUtils::Installed->modules()'
    
    libwww::perl
    
    perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed->files("libwww::perl")'
    
    /perl-5.26.2/lib/site_perl/5.26.2/LWP.pm
    43 more files...
    
    perl -MModule::Metadata -MData::Dumper -le' print(Dumper(Module::Metadata->new_from_module("libwww::perl")))'
    
    $VAR1 = undef;
    
    perl -MModule::Metadata -MData::Dumper -le' print(Dumper(Module::Metadata->new_from_module("LWP")))'
    
    $VAR1 = bless( {
                     'filename' => '/perl-5.26.2/lib/site_perl/5.26.2/LWP.pm',
                     'module' => 'LWP',
    
    perl -MExtUtils::Installed -le 'print join "\n", ExtUtils::Installed->files("LWP")'
    
    LWP is not installed at -e line 1.
    
    
How can I set binmode in oneliner
1 direct reply — Read more / Contribute
by TISON
on Sep 23, 2018 at 00:41
    oneliner "perl -e '...'" doesn't enable utf-8 encode by default, any idea to set perl use utf-8 encoding/unicode by default?
Dist::Zilla Tutorial for beginners
4 direct replies — Read more / Contribute
by nysus
on Sep 22, 2018 at 23:15

    As a new contributor to CPAN with the confusion of how to create a distribution still relatively fresh in my mind, I'd like to start a series of tutorials to help new cpan contributors make sense of Dist::Zilla. I think that the existing documentation for Dist::Zilla isn't really geared toward new module developers and generally assumes a basic familiarity with how to create module distributions without it. This is too bad because as confusing as it was for me to figure it out, I credit Dist::Zilla with saving me from a lot of the tedious work involved in module creation and it helped me create higher quality modules than I would have created without it. So my goal is to do what I can to help beginner perl module distributors to try to help them avoid the pain I experienced in putting Dist::Zilla to good use.

    I'm looking for feedback for my first tutorial in this series: "A 30,000 Foot View of Dist::Zilla and Software Distributions". If you can spare a few minutes to read it over and offer feedback, I'd appreciate it. Thanks!

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

What does "bad handshake" mean when connecting to mysql with DBD::mysql?
1 direct reply — Read more / Contribute
by Cody Fendant
on Sep 22, 2018 at 20:05
    • My sqld is up and running
    • I can connect to it just fine with a mysql client and PHPMyAdmin and select, update etc
    • However when I try to connect to it with DBD::mysql I get "bad handshake" in DBI->errstr()

    What kind of things can I check on? How can I debug this?

Dancer2::Plugin::Database and database errors
3 direct replies — Read more / Contribute
by lee_crites
on Sep 22, 2018 at 18:47

    Dancer2::Plugin::Database and database errors

    I have written an number of Dancer/Dancer2 applications, and really like using this framework. This time I decided to try out the Danver2::Plugin::Database. It certainly has made some things significantly easier, so I'm basically happy with the decision. But the problem I have is when there is an error, I have no idea what the error is. I'm doing a quick_select on a (SQLite) table that worked before. I made changes to the table structure and such, and now when I try to do the quick_select, it returns an error -- but I cannot figure out what the error is.

    This same database connection will do the quick_insert, so I'm pretty sure it isn't a database missing or database corrupt or whatever. So I'm lost.

    The (fairly limited) documentation states it is a subclass of DBI, so I tried using the ->err and ->errstr methods, neither one worked. The actual code I am using to get the info is:

    my $delstatus = 'checking for: [' . $data->{'host_name'} . '][' . $data->{'service_description'} . '] for last output + entry.'; my @last_records = database('current')->quick_select('states', { host_name => $data->{'host_name'}, name => $data->{'service_description'} }, { order_by => { desc => 'id' } } ) or $delstatus .= '/error from quick_select call;' . ' ERR [' . database('current')->err . '];' . ' ERRSTR [' . database('current')->errstr . ']'; $delstatus .= '/found [' . (scalar @last_records) . '] to dele +te'; debug("QUICK SELECT STATUS: --=> $delstatus <=--");

    And a sample response I am getting is:

    Use of uninitialized value in concatenation (.) or string at /home/svc +anagios/n2s/bin/../lib/NagiosToServiceNow/json.pm line 699. Use of uninitialized value in concatenation (.) or string at /home/svc +anagios/n2s/bin/../lib/NagiosToServiceNow/json.pm line 699.[NagiosToS +erviceNow::json:51461] debug @2018-09-22 15:41:00> QUICK SELECT STATU +S: --=> checking for: [targethostname][targetchecktext] for last outp +ut entry./error from quick_select call; ERR []; ERRSTR []/found [0] t +o delete <=-- in /home/svcanagios/n2s/bin/../lib/NagiosToServiceNow/j +son.pm l. 709

    So I know the two calls are not right. But also, a select from the command line for this particular check showed a count of 11 items. This pass made it 12 (the write is right after this block).

    I cannot imagine this module has been around this long with nobody else needing to get the error message(s) from the database, so I am certain it is there and avaiable; I'm just not finding it documented anywhere.

    So if you have the answer, I'll promise to pass good vibes about you into the universe for at least the next month... :D

    David Lee Crites
    lee@critesclan.com
Objects and passing/calling methods
1 direct reply — Read more / Contribute
by driador
on Sep 22, 2018 at 16:01
    Greetings all. This humble novice requests your assistance...

    Imagine I have a base package (SomePackage.pm) that performs a number of functions against a website with a restful interface. That package is written in a perl OO way, with a new() constructor. Another script (caller.pl) will be the user of this package.

    That said, I have a number of other sub modules in the base package: SomePackage::Auth.pm, SomePackage::Client.pm, SomePackage::Tickets.pm, etc.

    Auth provides the methods to handle authentication to a given site. Client provides a LWP::UserAgent and any methods around certain functions the website offers. Tickets provides methods to create/modify/manage tickets on the site.

    The goal I have here is that in the caller.pl, I instantiate the base package SomePackage->new; That sets up the base as well as setting up internal members to be a client (via SomePackage::Client) and ticket (via SomePackage::Ticket). It also has a method wrapper around SomePackage::Ticket's createTicket method:

    package SomePackage; use strict; use warnings; use SomePackage::Auth; use SomePackage::Client; use SomePackage::Ticket; sub new { my $class = shift; my $self = {}; SomePackage::Auth->getCredentials; $self->{client} = SomePackage::Client->new; $self->{ticket} = SomePackage::Ticket->new; bless $self, $class; return $self; } sub createTicket { my $self = shift; my $class = shift; my $project = shift; return $self->{ticket}->createTicket($self, $project); }

    Now, in caller.pl, I do something like

    my $packObj = SomePackage->new; $packObj->createTicket($project);

    On running caller.pl, I get use of unitialized value in subroutine entry. What is the proper way to structure classes/objects such that makes passing internal attributes/objects around painless? Am I going about this wrong way?

    TIA
    A perl OO newb
CPAN modules to read xlsx file in v.5.6
1 direct reply — Read more / Contribute
by Arunkumar_141
on Sep 22, 2018 at 13:19
    Hi, Need CAPN module details to read xlsx files in v.5.6
file handing
5 direct replies — Read more / Contribute
by bigup401
on Sep 22, 2018 at 09:17

    i want to open file and insert it into dir with new filename

    my $NFILE = "09911"; #NEW FILE NAME my $FILE = '02190.JPG'; #FILE TO OPEN my $openfile = open(DATA, ">$FILE"); #OPEN FILE my $newfile = rename($openfile, $NFILE); #RENAME FILE FROM 02190.JPG T +O 09911.JPG my $writefile = open(DATA,">>", "img/$newfile"); #INSERT THE FILE IN I +MG DIR WITH NEW NAME 09911.JPG close DATA;

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 chilling in the Monastery: (7)
    As of 2018-09-24 15:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Eventually, "covfefe" will come to mean:













      Results (191 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!