我有一个小的Perl程序,我想在命令行上运行.我需要require另一个其他人编写的Perl脚本(不是模块).反过来,这require是一些其他脚本.(我无法对这种方式做任何事情).
现在,这些脚本中的一个已经存在并且非常令人讨厌.我不要那个.每次出现故障时,我的控制台上都有15行,这让我很紧张.我试过了use CGI;use CGI::Carp qw(fatalsToBrowser)500 Internal Server Error page
require 'otherscript.pl';
no CGI;
no CGI::Carp;
Run Code Online (Sandbox Code Playgroud)
和
no CGI;
no CGI::Carp;
require 'otherscript.pl';
Run Code Online (Sandbox Code Playgroud)
卸载它,就像使用doc描述的那样,但它不起作用.
我可以以某种方式操纵符号表或做一些其他魔法来摆脱它吗?
我有一个软件可以XSL-FO从文本文件创建描述并将其转换为PDF文档.文本文件中的每一行都转换为fo:blockFO,听起来不对,但我现在无法改变它.我的文档包含1到3页的A4.
我现在需要做的是在现有文本下面添加一个宽约8厘米的图形.它应该是左对齐的.在它旁边,我想放置一个带有(长)描述的文本块.

我看了几个关于FO的文档并提出了这个:
<fo:block intrusion-displace="block" margin-top="20mm">
<fo:float float="right">
<fo:block margin-left="20mm">
Bacon ipsum dolor sit amet laborum proident...
</fo:block>
</fo:float>
<fo:external-graphic src="image.png"/>
</fo:block>
Run Code Online (Sandbox Code Playgroud)
这似乎是我想要的(当然经过一些微调),但遗憾的是FOP 还不支持 fo:float.
似乎还有一种方法可以创建多个列(没有表格),但我无法弄清楚它是如何工作的.一个似乎需要一个新的页面,但如果有可用的空间我需要使用当前页面(我猜我不必关心).
所以我的问题是:还有另一种方法可以不使用它来构建它fo:float吗?
我是Perl的新手.我有excel文件说"sample.xls",如下所示. Sample.xls
有大约这样的1000行数据.我想解析这个文件并将其写在另一个文件中,如下所示输出格式为"output.xls".
output.xls 我在perl中编写了一个脚本,然而,它并没有按照我想要的方式给出确切的输出.此外,看起来脚本效率不高.任何人都可以指导我如何改进我的脚本以及输出如"output.xls"所示?
这是脚本:
#!/usr/bin/perl –w
use strict;
use warnings;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Chart;
# Read the input and output filenames.
my $inputfile = "path/sample.xls";
my $outputfile = "path/output.xls";
if ( !$inputfile || !$outputfile ) {
die( "Couldn't find file\n" );
}
my $parser = Spreadsheet::ParseExcel->new();
my $inwb = $parser->parse( $inputfile );
if ( !defined $inwb ) {
die "Parsing error: ", $parser->error(), ".\n";
}
my $outwb = Spreadsheet::WriteExcel->new( $outputfile );
my $inws = $inwb->worksheet( "Sheet1" …Run Code Online (Sandbox Code Playgroud) 我试图计算从数据库中提取的两个日期之间的日历天数.我认为将日期转换为秒将是一个简单而正确的解决方案.
#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(strftime);
use Date::Parse;
my $minDate = "2016-03-27";
my $maxDate = "2016-06-15";
print "Format as extracted from db: mindate: $minDate and maxdate: $maxDate\n";
my ($dbYear,$dbMonth,$dbDay) = split ('-', $minDate);
my $datum = "$dbYear$dbMonth$dbDay";
my $minDateSec = str2time($datum);
($dbYear,$dbMonth,$dbDay) = split ('-', $maxDate);
$datum = "$dbYear$dbMonth$dbDay";
my $maxDateSec = str2time($datum);
my $numCalDaysSec = ($maxDateSec-$minDateSec)/86400;
print "Min date in Seconds: $minDateSec\n";
print "Max date in Seconds: $maxDateSec\n";
print "Num days: $numCalDaysSec\n";
Run Code Online (Sandbox Code Playgroud)
最初,我认为这种方法为我提供了可靠的结果:
bash-3.2$ ./testNumDays.pl
As …Run Code Online (Sandbox Code Playgroud) 我想在一个独立的脚本中使用Mojolicious渲染引擎渲染.html.ep模板,该脚本发送电子邮件并从cron运行:
#!/usr/bin/perl
use feature ':5.10';
use Mojo::Base -strict;
use Mojolicious::Renderer;
use Data::Dumper;
my $renderer = Mojolicious::Renderer->new();
push @{$renderer->paths}, '/app/templates';
my $template = $renderer->get_data_template({
template => 'template_name',
format => 'html',
handler => 'ep'
});
print Dumper($template) . "\n";
Run Code Online (Sandbox Code Playgroud)
但是,$template始终未定义.
模板文件是/app/templates/template_name.html.ep.
我究竟做错了什么?
我已经阅读了http://www.perl101.org/subroutines.html但我只是不了解可选参数.
我想在PDF :: API2中调用以下子.该文件称"-indent"是一种选择.我如何为缩进20传递参数?
这就是我现在所经过的:
$txt->section($str, $contentwidth,$heightmax);
Run Code Online (Sandbox Code Playgroud)
这是子
Run Code Online (Sandbox Code Playgroud)sub section { my ($self,$text,$width,$height,%opts)=@_; my $overflow = ''; foreach my $para (split(/\n/,$text)) { if(length($overflow) > 0) { $overflow .= "\n" . $para; next; } ($para,$height) = $self->paragraph($para,$width,$height,%opts); $overflow .= $para if (length($para) > 0); } if (wantarray) { return ($overflow,$height); } return $overflow; }
在Eclipse中使用Perl EPIC调试器时,为什么执行不会在'do'模块的断点处停止,而是停在'require'模块?
script.pl
use strict;
#use sample; # <-- Execution stops at breakpoint in printMessage() of 'sample.pm'
#require sample; # <-- Execution stops at breakpoint in printMessage() of 'sample.pm'
#do 'sample.pm'; # <-- Execution DO NOT STOP at breakpoint in printMessage() of 'sample.pm'
sample::printMessage();
Run Code Online (Sandbox Code Playgroud)
sample.pm
package sample;
sub printMessage
{
print 'new message!';
}
1;
Run Code Online (Sandbox Code Playgroud) 是否可以使用Excel :: Writer :: XLSX更改或声明默认字体?我每次创建或添加图表和单元格时都可以设置它.但我认为应该有一个更简单的方法.
我是Perl新手,我目前正在学习Perl如何处理多维数组以及如何访问元素.
数据库查询在子例程中执行,并返回数组@stash:
...
while ( $array_ref = $sth->fetchrow_arrayref ) {
push @sub_stash, [ @$array_ref ];
}
$dbh->disconnect;
return ( @sub_stash );
Run Code Online (Sandbox Code Playgroud)
@stash是在main中接收的,并且管理打印数组的内容如下:
@stash = query($var);
### Dump the stash contents!
foreach my $array_ref ( @stash ) {
print "@$array_ref\n";
}
Run Code Online (Sandbox Code Playgroud)
屏幕输出的示例如下:
bash-3.2$ ./test_db_array.pl
2007 123 200728 200753 26
2008 256 200800 200852 53
2009 256 200900 200952 53
2010 258 201001 201052 52
2011 257 201101 201152 52
2012 256 201201 201253 53
2013 255 201300 201352 53
2014 254 …Run Code Online (Sandbox Code Playgroud) 我有一个字符串
my $foo = 'one#two#three!four#five#six';
Run Code Online (Sandbox Code Playgroud)
从中我想要提取由a #或a 分隔的部分!.这很容易split:
my @parts = split /#|!/, $foo;
Run Code Online (Sandbox Code Playgroud)
另外一个要求是我还需要捕获感叹号.所以我试过了
my @parts = split /#|(!)/, $foo;
Run Code Online (Sandbox Code Playgroud)
然而,这会返回一个undef值或感叹号(在拆分规范中也明确说明).
所以,我用以下方法清除了不需要的undef值grep:
my @parts = grep { defined } split /#|(!)/, $foo;
Run Code Online (Sandbox Code Playgroud)
这就是我想要的.
然而,我想知道我是否可以以某种方式更改正则表达式,以便我不必也调用grep.
perl ×9
apache-fop ×1
cgi ×1
debugging ×1
eclipse ×1
epic ×1
mojolicious ×1
regex ×1
subroutine ×1
xlsx ×1
xsl-fo ×1