首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于perl tie::文件模块

关于perl tie::文件模块
EN

Stack Overflow用户
提问于 2013-01-17 23:53:47
回答 1查看 354关注 0票数 0

关于tie::file模块,我有两个疑问

  1. 我使用了tie::file模块来搜索一个55 MB的文件,并在tie::file中设置了20 MB的内存。当我试图在绑定数组上搜索字符串时,这需要很长时间。这附近有什么工作吗?
  2. 可以绑定:用于读取二进制文件的文件。绑定数组由"\n“分隔。如何使用tie::file来读取二进制文件?请给我贴上一些代码样本。

/home/a814899> perl -e的打印"x\n"x27 for 1.1024*1024;‘>a

/home/a 814899> echo "hello world“>> a

代码语言:javascript
复制
Using Unix grep

/home/a814899> time grep "hello " a
hello world

real    0m8.280s
user    0m8.129s
sys     0m0.139s

Using the regex

/home/a814899> (time perl -e 'while (<>) { if (/hello/) { print "hello world"} }' a)
hello world
real    0m51.316s
user    0m51.087s
sys     0m0.189s


Using Perl Grep

#!/usr/bin/perl
print "executing\n";
my $outputFileDir="/home/a814899";
my $sFileName="a";
open my $fh, "<", $outputFileDir . "/" . $sFileName or do {
       print "Could not open the file";
    };
print "success  in open" . "\n";
my @out=grep {/hello world/} <$fh> ;
print "@out" ;
close($fh)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-18 01:03:08

  1. 是。 使用Tie::File,您可能就是这样做的: $( time perl -MTie::File -e‘tie @a,"Tie::File",$ARGV;for (@a) { if (/y/) {}}’a) 2>&1 grep ral2m44.333s 这就是“解决办法”: $( time perl -e‘while (<>) { if (/y/) {}}’a) 2>&1 \ grep实0m0.644 s 数据文件是使用 $ perl -E‘’say "x"x54 for 1.1024*1024;‘>a
  2. 文件不读取文件;Tie::File提供了将文件的行映射到数组元素的方法。因为“二进制”文件没有行,所以使用Tie::File访问一行没有任何意义。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14390289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档