Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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
net::ssh::expect net::scp::expect problem
No replies — Read more | Post response
by bigswifty00000
on Oct 07, 2015 at 13:48
    Greeting Monks!

    I'm having a problem with the above, on one server out of three. That server is running mac osx 10.7.5. The local server is mac osx 10.6.8

    I can manually from the command line both ssh, and scp a file.

    On the remote server, I've reviewed permissions, removed and reinstated the keys etc. etc.

    Any and all help appreciated!


    These are the outputs from the ssh and scp.

    Uncaught exception from user code: SSHAuthenticationError Login timed out. The input stream currently has the contents bellow: Last login: Wed Oct 7 13:10:19 2015 from xxxx-idx-dev3:~ user$ at /System/Library/Perl/Extras/5.10.0/ line 828. at /Library/Perl/5.10.0/Net/SSH/ line 209. Net::SSH::Expect::__ANON__('ARRAY(0x100eb2730)') called at /System/Library/Perl/Extras/5.10.0/ line 828 Expect::_multi_expect(1, 'ARRAY(0x100eb2a60)', 'ARRAY(0x100eb2b68)') called at /System/Library/Perl/Extras/5.10.0/ line 565 Expect::expect('Expect=GLOB(0x100eb25c8)', 1, 'ARRAY(0x100eb2ca0)', 'ARRAY(0x100eb2e18)', 'ARRAY(0x100eb20e8)', 'ARRAY(0x100e7d548)', 'ARRAY(0x100eb26b8)') called at /Library/Perl/5.10.0/Net/SSH/ line 580

    Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x100e7d4a0)', 1, 'ARRAY(0x100eb2ca0)', 'ARRAY(0x100eb2e18)', 'ARRAY(0x100eb20e8)', 'ARRAY(0x100e7d548)', 'ARRAY(0x100eb26b8)') called at /Library/Perl/5.10.0/Net/SSH/ line 213

    Net::SSH::Expect::login('Net::SSH::Expect=HASH(0x100e7d4a0)') called at ./ line 200 main::ssh_login('', 'user', 'password') called at ./ line 154

    main::copy_exist_to_old_all_servers('ARRAY(0x100e7d440)', 'ARRAY(0x100eaa830)') called at ./ line 53

    Uncaught exception from user code: Problem performing scp: Executing: program /usr/bin/ssh host, user user, command scp -v -t /Users/user/Project/scripts/perl_scripts/ OpenSSH_5.2p1, OpenSSL 0.9.8y 5 Feb 2013 Sending file modes: C0755 13728 Sink: C0755 13728 at ./ line 86. at /Library/Perl/5.10.0/Net/SCP/ line 224.

    Net::SCP::Expect::scp('Net::SCP::Expect=HASH(0x100eaa9e0)', '/Users/user/cvs/xxxx/Project/xxxx/xxxx/rest_...', '/Users/user/Project/scripts/perl_scripts/xxxx_...') called at ./ line 86

    main::scp_to_remote_new_all_servers('ARRAY(0x100e7d488)', 'ARRAY(0x100eaa878)') called at ./ line 55

write my own DBD / DBI drivers
1 direct reply — Read more / Contribute
by WolliK
on Oct 07, 2015 at 13:29
    Hi Monks,

    I have to write my own DBD/DBI driver(s) from scratch for the two DBs: SQL/MP and SQL/MX that are not listed on CPAN.

    Please can you point me to a tutorial for writing DBD and DBI drivers ? Or have some of you done this before ?

    Regards wollik
Slicing a hash reference from a collection of hash references within a hash reference
3 direct replies — Read more / Contribute
by nysus
on Oct 07, 2015 at 11:21
    This is an embarrassingly newbie question, but I have a mental block when it comes to references. Given the following simple data structure, how do I get a slice of the name data?
    $household = { 23 => { last => 'Smith', first => 'Mary' }, 22 => { last => 'Jones', first = 'Bob' } };
    Here's my newbie code that works:
    my $key = 23; my $person = $household->{$key}; my %name = %$person; my @slice = @name{'first', 'last'};
    How do I turn this into a one liner?


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

CGI - Get all params and their associated values
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 07, 2015 at 10:26
    In light of what is the safe way to get all the params and their associated values?
Perl module path not found
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 07, 2015 at 09:18
    Hi Monks!

    My code runs fine, I can even run it from the browser and it does what it is supposed do to, but I can’t get it to work running from a “cron job”, I tried everything, I had the "” locally, meaning in the same directory level as the “”, now I have it inside of "lib" directory, but it is still giving me this error:
    Can't locate in @INC (@INC contains: .. /etc/perl /usr/loca +l/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/li +b/site_perl .) at /home/ line 10. BEGIN failed--compilation aborted at /home/ line 10.

    The directory structure looks like this:
    .. /cgi-bin /lib/ /scripts/ ..
    Here is the part of the code:
    #!/usr/bin/perl use strict; use warnings; use CGI qw(escapeHTML); use Data::Dumper; use Date::Calc qw( Today_and_Now ); use lib '..'; # Add private library to path use DBStuff; ####>>>>>>>>>>>>>> This is my line 10 use MyLib::Log qw(do_log); if ($@) { warn "Cron job failed: $@\n"; } my $q = new CGI; $| = 1; BEGIN { my $log_error = 'error.txt'; use CGI::Carp qw(carpout); # Send all warnings to the log_file open STDERR, '>>', $log_error; } ...
    Any suggestions?
    Thanks for looking!
[Moose] extends(...) throws "Subroutine redefined" warnings
2 direct replies — Read more / Contribute
by muba
on Oct 07, 2015 at 08:16

    I have a superclass (MyClass), which creates instances of a subclass on demand. MyClass implements a custom method "get_subclass_instance" for this. The subclass (SubClass) extends 'MyClass';, however, this generates a "Subroutine get_subclass_instance redefined" warning.

    Minimal example:

    # package MyClass; use SubClass; use Moose; sub get_subclass_object { return SubClass->new; } 1;
    # package SubClass; use Moose; extends 'MyClass'; 1;
    $ perl -MMyClass -e 0 Subroutine get_subclass_object redefined at line 5. $

    I understand that extends(...) tries to load the class(es) passed to it. Consequently, if I remove the Extends 'MyClass' line from, the warning disappears.
    But I don't want to remove that line, because SubClass does extend MyClass!

    Of course, I could simply ignore the warning, but that doesn't feel clean to me. So what am I doing wrong, and how can I have MyClass load and instantiate SubClass, while SubClass explicitly extends MyClass?

Dynamically create the hash reference
2 direct replies — Read more / Contribute
by k_manimuthu
on Oct 07, 2015 at 06:16

    Hi All,

    I am trying to create dynamic references in a recursion function. Below I place code which I try, and it return '{}' only. How to get the initial level reference in else part?

    use Data::Dumper; sub insert { my ($ref, $head, @tail) = @_; return unless ( @tail ); if ( @tail and $head ne 'break') { insert( \%{$ref->{$head}}, @tail +) } else { # Here $ref gives '{}' value only. # How to get values of previous head values (ie. f1,f2,f3) print "\n==>", Dumper $ref; # More commands . . . #insert( \%{$ref->{f1}}, @tail ) } } my %hash; while (<DATA>) { chomp and insert \%hash, split( '/', $_ ) ; } print "\nDump\n", Dumper %hash; __DATA__ f1/f2/f3/f4/break/f1/f2/f5/break/f1/f2/f6
Can't use string as an ARRAY ref
1 direct reply — Read more / Contribute
by OldMonkRum
on Oct 07, 2015 at 02:16
    Hi Monks,

    In Getopt I have "tlef:s@" => \$optsHash->{tlef}, which could be single or array. I moved to 5.20.2

    if($self->{tlef}){ if(@{$self->{tlef}}) {

    If tlef is defined once then I want to check if its an array. Previously if if(defined @{$self->{tlef}}) { was working. Now its deprecated, so if I remove define, I get the cant use string as ref issue. Is there an easy way to check if the command line option from GetOpt is array or single element?

Subroutine naming convention/style
4 direct replies — Read more / Contribute
by Cody Fendant
on Oct 07, 2015 at 00:20

    I'm trying to write code to access an API.

    In that API there's an "either add or update" method for an object.

    Whether you're adding or updating that object, you provide an ID. If that ID is found in their database, then you're updating that object. If not, you're adding it.

    What would you call your subroutine which either added or updated a Widget?

    Would you call it: addOrUpdateWidget() because that at least matches their API call (longwinded names are all over the place).

    Would you have two subroutines addWidget() and updateWidget() to make it more transparent what the user was trying to do, and let you give a warning "you thought you were updating a Widget! Turns out you added it instead."?

    Would you call it just widget()?

[OT] HTTP downloads and caching
1 direct reply — Read more / Contribute
by syphilis
on Oct 07, 2015 at 00:00

    A couple of days back I uploaded a new version of Math-Float.ppd. (It's only 4kb, so feel free to download it and tell me if you get the same version of that file as I do - detailed below.)

    I've verified that the upload was successful - if I download it via scp I get the "new" version of the file back, as expected.
    But if I download it in a browser (including IE on Windows, FF on Ubuntu, and IceWeasel on Debian, or if I download it with LWP::Simple, or if I download it using wget, then I get the "old" version of that file.
    The 2 files differ only in that the contents of the "old" file match the string 07 and don't match the string 08 - and vice versa for the "new" version of the file.


    1) If you perform a http download, which version of Math-Float128.ppd do you get ? ... the "old" version that matches 07 (as I do) ? ... or the "new" version that matches 08 (as should happen) ?

    2) Why am I seeing the behaviour that I do ?

    I've deleted histories and emptied the browser caches on both IE and FF.
    And, on the Windows 7 box, I've cleared the DNS cache (ipconfig /flushdns). What's the corresponding command for Linux ?
    Yet I still get the "old" superceded version for each of the above-mentioned http download methods.

    Where can this cache be held ? (The company that hosts the website says it can't possibly be their fault - and when they use wget they get the "new" version of the file.)
    Could it be something that my ISP is doing ?
    What else can I do to try and address this annoyance ?

    Thanks for any help (but also feel free to ignore).


Add your question
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
  • 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?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2015-10-07 17:59 GMT
    Find Nodes?
      Voting Booth?

      Does Humor Belong in Programming?

      Results (194 votes), past polls