如果我的Perl代码有一个生产代码位置和"beta"代码位置(例如生产Perl代码我们/usr/code/scripts,BETA Perl代码在/usr/code/beta/scripts;生产Perl库,/usr/code/lib/perl并且这些库的BETA版本都在/usr/code/beta/lib/perl,对我来说是否有一个简单的方法实现这样的设置?
具体要求是:
代码必须是生产和BETA位置的相同.
为了澄清,为了将任何代码(库或脚本)从BETA推广到生产,需要发生的唯一事情就是cp从BETA向prod位置发出命令 - 文件名和文件内容必须保持相同.
BETA版本的脚本必须调用其他BETA脚本和BETA库(如果存在)或生产库(如果BETA库不存在)
BETA和生产之间的代码路径必须相同,但基目录(/usr/code/vs /usr/code/beta/)除外
这些脚本必须全部相同的基本目录下,但他们可能会在其子目录中的任意深度的水平(这排除了经典use lib "$FindBin::Bin/../lib"的部分解决方案31.13.使用LIB的"的Perl编程")
我将介绍我们如何解决问题作为这个问题的答案,但我想知道是否有更好的方法.
是否可以添加标题(带有文本和一个图像)和页脚(带页码)和图像.我在下面写了代码来创建一个显示png图像的PDF文档.
如果这可以通过任何其他模块轻松完成,请建议.非常感谢您回复示例代码.
use strict;
use PDF::API2::Lite;
use Getopt::Long;
my $outfile;
my $path;
my $options = GetOptions( "outfile=s" => \$outfile,
"images=s" => \$path,);
my @images = sort glob("$path") or die "No Files\n";
my $pdf = PDF::API2::Lite->new();
for my $png ( sort @images ) {
my $image = $pdf->image_png( "$png" );
$pdf->page(1150,450);
$pdf->image($image, 10, 10);
}
$pdf->saveas( $outfile );
Run Code Online (Sandbox Code Playgroud) 我似乎被困在尝试访问另一个包中定义的标量,并将示例缩小到一个简单的测试用例,我可以重现这个问题.我希望能够使用我们的机制访问对包'Example'中定义的列表的引用,但是,Dumper显示该变量在example.pl中始终未定义:
Example.pm如下所示:
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
package Example;
use Data::Dumper;
my $exported_array = [ 'one', 'two', 'three' ];
print Dumper $exported_array;
1;
Run Code Online (Sandbox Code Playgroud)
使用此包的代码如下所示:
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
use Data::Dumper;
use lib '.';
use Example;
{ package Example;
use Data::Dumper;
our $exported_array;
print Dumper $exported_array;
}
exit 0;
Run Code Online (Sandbox Code Playgroud)
在运行此代码时,第一个Dumper运行并且事情看起来正常,此后,第二个Dumper,example.pl运行,然后引用未定义:
$VAR1 = [
'one',
'two',
'three'
];
$VAR1 = undef;
Run Code Online (Sandbox Code Playgroud) 这是我的问题.我正在运行OS X v10.7(Lion)并且想要设置我编写的旧Perl程序(然后使用带有ActivePerl的Windows系统然后使用其ppm).
我读过使用CPAN来安装Perl模块(我正在尝试安装Graph模块).每当我尝试安装它时,它都会因拒绝连接而失败.为什么?所以我读到我应该运行以下内容来更新CPAN并修复任何损坏的链接:
cpan> install Bundle:CPAN
cpan> reload cpan
cpan> index cpan
cpan> exit
Run Code Online (Sandbox Code Playgroud)
但是,执行此操作后,每次尝试进行CPAN安装或升级时,我都会遇到这种情况:
New CPAN.pm version (v1.9800) available.
[Currently running version is v1.9456]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
Run Code Online (Sandbox Code Playgroud)
我试图使用OS X中包含的默认Perl内容而不是下载ActivePerl.如何修复CPAN并安装图形模块?
PS:运行安装CPAN并重新加载CPAN没有做任何事情,但它生成了相同的消息.
更新 我能够通过终端升级到v1.9800进行手动安装(make,install).但我仍然无法安装图形模块.这是我得到的:
http://cloud.jjnford.com/3D1C1H4217222b1p1O3a
更新 - 问题已解决 我终于能够解决问题了.我刚刚将/User/jj/.cpan目录移动到User/jj/.cpan_bak,然后重新配置了CPAN和安装的Graph Module,没有大惊小怪.
PREREQ_PM 指定运行时先决条件,但是如何指定运行测试用例所需的模块?
我应该用BUILD_REQUIRES它吗?
我在perl中遇到了处理内存的奇怪问题.我正在使用一个使用相当大的哈希结构的perl应用程序.我正在为来回对象指定has ref.但最后似乎即使我要释放对象和哈希值,内存使用量也保持不变.
以下是问题的示例:
my $hash = {};
.............
this ds gets populated with a lot of data ...
.......
{
my $obj = new Class("data"=>$hash);
.......
.......
......
}
#even undefing the $hash
undef $hash;
# I can expect some improvement in Memory Utilization, but its not happening
Run Code Online (Sandbox Code Playgroud)
我想我正在做一些非常基本的错误.任何人都可以建议吗?
我想安装运行Circos所需的模块.其中一个必需的模块是GD.
brew install libgd*以下 cpan[1]> install GD
Test Summary Report
-------------------
t/GD.t (Wstat: 0 Tests: 12 Failed: 1)
Failed test: 10
Files=2, Tests=13, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.11 cusr 0.02 csys = 0.15 CPU)
Result: FAIL
Failed 1/2 test programs. 1/13 subtests failed.
make: *** [test_dynamic] Error 255
LDS/GD-2.46.tar.gz
/usr/bin/make test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
reports LDS/GD-2.46.tar.gz …Run Code Online (Sandbox Code Playgroud) 我试图学习Perl,我正在使用OS-X 10.8.4并拥有Perl版本:
这是为darwin-thread-multi-2level构建的perl 5,版本12,subversion 4(v5.12.4)
我正在尝试运行此代码:
#!/usr/bin/env perl
use strict;
use warnings;
my $a = 1;
my $b = 1;
say $a + $b ;
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
Can't call method "say" without a package or object reference at test2.pl line 10.
Run Code Online (Sandbox Code Playgroud)
谢谢!
背景:
错误:
defined(%hash) is deprecated at pm/Alerts/Alerts.pm line 943.
(Maybe you should just omit the defined()?)
defined(%hash) is deprecated at pm/Alerts/Alerts.pm line 944.
(Maybe you should just omit the defined()?)
Run Code Online (Sandbox Code Playgroud)
码:
###
# Iterate the arrays deleting identical counts from each.
# If we found a mismatch then die.
# If either array is not empty when we are done then die
$logger->info('Comparing ' . (scalar keys %cms_rows) . ' CMS symbols to …Run Code Online (Sandbox Code Playgroud) 是否有实现数据库功能且易于使用的perl模块。我不需要用于连接某些数据库产品的模块。我需要用perl编写简单的数据库。
谢谢。