我有一个巨大的xlsx文件(大约127 MB),并希望使用Spreadsheet::Excel模块阅读,但我在2GB RAM机器上得到" Out of Memory"错误.(注意脚本适用于较小的excel 2007文件)
有没有办法在不达到内存限制的情况下逐行读取excel文件.搜索谷歌我遇到了http://discuss.joelonsoftware.com/default.asp?joel.3.160328.14,但我并不熟悉如何将电子表格存储到标量中.有人可以将excel 2007文件作为标量和打印单元格值进行读取.下面是我在较小的电子表格上运行的当前脚本.
#!/usr/bin/perl
use Excel::Writer::XLSX;
use Spreadsheet::XLSX;
my $workbook = Excel::Writer::XLSX->new('Book1.xlsx');
my $worksheet = $workbook->add_worksheet();
# use strict;
my $excel = Spreadsheet::XLSX -> new ('Book2.xlsx');
my $date_format = $workbook->add_format();
$date_format->set_num_format('dd/mm/yy hh:mm');
# Columns of interest
@columns=(0,1,2,5,9,10,12,13,31);
@reportlist=("string1","String2","String3");
@actuallist=("ModifiedString1","ModifiedString2","ModifiedString3");
$max_list=$#reportlist;
foreach my $sheet (@{$excel -> {Worksheet}}) {
printf("Sheet: %s\n", $sheet->{Name});
$sheet -> {MaxRow} ||= $sheet -> {MinRow};
foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) …Run Code Online (Sandbox Code Playgroud) 如何将电子邮件解析为标题,正文,附件以及发件人和收件人等部分?我想使用Perl或Perl Moose?
我刚刚开始使用Perl 1周前,我是一个编程newbee.请帮助,因为我的公司项目依赖于此.
情况:
我想打开一个XML文件,在这个例子中是Library.xml,并使用特定的"ISBN"编号编辑XML文档.找到ISBN号后,我想用匹配的"ISBN"号码更改特定书籍的页数.
问题:
现在,我可以做到以上但是,我需要保存更新的XML,使用相同的名称"library.xml",并保持原始XML文档的XML结构.这是我难倒的地方.我尝试过使用XML :: DUMPER和XML :: TWIG以及其他可能但都失败了.
原始XML文档:
library.XML看起来像这样:
<library>
<book>
<title>Perl Best Practices</title>
<author>Damian Conway</author>
<isbn>0596001738</isbn>
<pages>542</pages>
<image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif"
width="145" height="190" />
</book>
<book>
<title>Perl Cookbook, Second Edition</title>
<author>Tom Christiansen</author>
<author>Nathan Torkington</author>
<isbn>0596003137</isbn>
<pages>964</pages>
<image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif"
width="145" height="190" />
</book>
<book>
<title>Guitar for Dummies</title>
<author>Mark Phillips</author>
<author>John Chappell</author>
<isbn>076455106X</isbn>
<pages>392</pages>
<image src="http://media.wiley.com/product_data/coverImage/6X/07645510/076455106X.jpg"
width="100" height="125" />
</book>
</library>
Run Code Online (Sandbox Code Playgroud)
代码:
以下是我试图操作但没有成功的代码.
#!/usr/bin/perl
use strict;
use warnings;
#use XML::Simple qw(:strict);
use XML::LibXML;
use XML::Dumper;
my $dump = new XML::Dumper; …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个独特的数组,无论其原始顺序如何,并且不使用任何模块,这是我到目前为止所提出的:
my @arr = qw(b a a c d g e f);
my %hash;
@hash{@arr}=();
say keys %hash;
Run Code Online (Sandbox Code Playgroud) 考虑示例代码:
$VAR1 = {
'en' => {
'new' => {
'style' => 'defaultCaption',
'tts:fontStyle' => 'bold',
'id' => 'new'
},
'defaultCaption' => {
'tts:textAlign' => 'left',
'tts:fontWeight' => 'normal',
'tts:color' => 'white',
}
},
'es' => {
'defaultSpeaker' => {
'tts:textAlign' => 'left',
'tts:fontWeight' => 'normal',
},
'new' => {
'style' => 'defaultCaption',
'tts:fontStyle' => 'bold',
'id' => 'new'
},
'defaultCaption' => {
'tts:textAlign' => 'left',
'tts:fontWeight' => 'normal',
}
}
};
Run Code Online (Sandbox Code Playgroud)
我将它作为参考返回,返回\%hash
我怎么解除这个?
如何从特定数字中获取值?
让我们说数字是20040819.我想得到最后两位数,即19使用Perl.
我需要一个Perl脚本,它将数字作为输入示例222,它应该输出为二百二十二.
chomp($myString);
$myString =~ s/\///g;
Run Code Online (Sandbox Code Playgroud)
我可以用这两个替换
$myString =~ s/\s//g;
Run Code Online (Sandbox Code Playgroud)
有什么区别吗?请解释.
鉴于array @A我们想要检查element $B它是否在其中.一种方法是这样说:
Foreach $element (@A){
if($element eq $B){
print "$B is in array A";
}
}
Run Code Online (Sandbox Code Playgroud)
然而,当它到达Perl时,我总是在思考最优雅的方式.这就是我的想法:如果我们将A转换为变量字符串并使用,有没有办法找出数组A是否包含B
index(@A,$B)=>0
Run Code Online (Sandbox Code Playgroud)
那可能吗?
我正在尝试做一些简单的数学运算
$example = (12 - 4);
Run Code Online (Sandbox Code Playgroud)
但是我需要单个数字的答案,在他们面前有一个0,所以$ example应该是
08 not 8
Run Code Online (Sandbox Code Playgroud)
我知道我可以做点什么
if ($example < 10){
$result = "0$example";
}
Run Code Online (Sandbox Code Playgroud)
但我必须认为,在进行这样的简单数学运算时,有一种方法可以指定输出的数字位数.