perl-module

JSON::XS “Usage” croak

删除回忆录丶 提交于 2019-12-10 14:18:20
问题 I can't seem to use JSON::XS 's OO interface properly. The following croaks with an error I can't track down: use JSON::XS; my $array = ['foo', 'bar']; my $coder = JSON::XS->new->utf8->pretty; print $coder->encode_json($array); This croaks with the following: Usage: JSON::XS::encode_json(scalar) at test.pl line 5. I have been combing through the code for JSON::XS and I can't find a "Usage:" warning anywhere. My usage seems to be pretty well matched with the examples in the documentation. Can

ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xdb00080, needed 0xdb80080)

安稳与你 提交于 2019-12-10 12:34:56
问题 For some reason, whenever I run any Perl module (like cpanm), I've been getting this response: ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0xdb00080, needed 0xdb80080) I'm not sure why this is happening. There doesn't seem to be any additional stacktrace, and even though there have been numerous bug reports and questions on this error, I was unable to find a solution. I'm running Ubuntu 17.04. Edit: I'm running the default installation of Perl that ships

How to read the password from the text file in perl

夙愿已清 提交于 2019-12-10 12:13:12
问题 I am new to perl script, The below code is downloading the files from sftp server. #!/usr/bin/perl use strict; use warnings; use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new( 'auser@sftp.rent.com', password => 'auser123', more => ['-v'] ); $sftp->get('outgoing/DATA.ZIP', '/home/sar/') or die "unable to retrieve copy: ".$sftp->error; $sftp->disconnect; Here i have hard codded the password, I want to avoid password in the script, Is there any other method to read the password from the

How can I 'use' specific version of a perl CPAN module?

我的未来我决定 提交于 2019-12-10 04:17:25
问题 I have a lot perl code that does different things in test and production, and I want to lock my code to specific versions of CPAN modules in case there are some changes to some of them in the future which may possibly break my code. So I want to use specific versions of all the modules I use. By use I mean use XML::Smart 回答1: To use specific module refer only use only MyModule => 0.30; Also to print error if module version you want is above to currently installed one You can say use XML:

How to include a file that contains all the required Perl module names?

 ̄綄美尐妖づ 提交于 2019-12-09 17:58:57
问题 The perl scripts contain all the module names in the beginning of the script. Ex: use strict; use XML::Parser; use XML::Simple; use DBI; use DBD::DB2::Constants; use POSIX qw( strftime ); use Storable qw(dclone); use Data::Dumper; use Carp; How to keep all the module names in another file and include the file in main perl script ? Thanks. 回答1: Create your own module. But, if if you make package in this module those strftime etc will be imported into another namespace. You can do litle hack to

How to print out Nagios Service UP Time Percentage from Nagios-Report Perl Module

时光毁灭记忆、已成空白 提交于 2019-12-09 17:56:11
问题 I can print out Host UP Time percentage from Nagios-Report Perl Module with following code: #!/usr/bin/perl use strict ; use Nagios::Report ; my $x = Nagios::Report->new(q<local_cgi localhost nagiosadmin>) or die "Can't construct Nagios::Report object." ; $x->mkreport( [ qw(HOST_NAME PERCENT_TOTAL_TIME_UP) ], sub { my %F = @_; my $u = $F{PERCENT_TOTAL_TIME_UP}; $u =~ s/%//; }, 0, sub { my $F = shift @_ ; } ) ; $x->debug_dump ; But How can I only print out Service UP Time Percentage? I mean

How do I make private functions in a Perl module?

廉价感情. 提交于 2019-12-08 22:44:30
问题 I am working on a little Perl module and for some reason I had the test driver script that was using my new module call one of the functions that I thought would be private, and it was successful. I was surprised, so I started searching google and I couldn't really find any documentation on how to make private functions in Perl modules... I saw one place that said to put a semicolon after the closing brace of your "private" function, like this: sub my_private_function { ... }; I tried that,

What does Perl do when two versions of a module are installed?

走远了吗. 提交于 2019-12-08 18:44:56
问题 I don't have root access on a remote box I'm working with, so I'm using a combination of cpanm and local::lib as described here to install CPAN modules to my local directory on the box. Using cpanm, I assume cpanm Module::To::Update would install the newest version of the module in my local library. Apparently, I don't need root access to upgrade my modules with CPAN, as I just tried it, and the upgrade went swimmingly. However, I'm still curious which version of the module Perl will use: the

How should I organize many Perl modules?

天涯浪子 提交于 2019-12-08 15:52:01
问题 Consider that I have 100 Perl modules in 12 directories. But, looking into the main Perl script, it looks like 100 use p1 ; use p2 ; etc. What is the to best way to solve this issue? 回答1: It seems unlikely to me that you're use ing all 100 modules directly in your main program. If your program uses a function in module A which then calls a function from module B, but the main program itself doesn't reference anything in module B, then the program should only use A . It should not use B unless

How do Perl modules “work”? [closed]

匆匆过客 提交于 2019-12-08 14:20:48
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am confused about Perl modules. I get that a module can be used to dump a whole bunch of subs into, tidying main code. But, what is the relationship between modules? Can modules "use" other modules? Must I use export, or can I get away with dropping that stuff? How do I solve