由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a question of perl
相关主题
请看看这个Perl random sampling code 有什么问题,python gc question
Perl 6 改动很大很恶心perl question: can I have a key of hash to be
javascript问个基本 C array 问题
int *a [] 和int (*a)[] 一样吗一个nested class的问题
a simple question求教一个perl问题
Perl里面$,@,#等字符问题请问perl程序能不能加运行参数?
一道面试怪题C++. (转载)紧急求助
简单的perl问题问C++文件路径的问题
相关话题的讨论汇总
话题: perl话题: argv话题: file话题: array话题: question
进入Programming版参与讨论
1 (共1页)
z*y
发帖数: 1311
1
I want to declare an array of file pointers. For example in C, it will look
like: FILE *fp[n].
However, I don't know how to do it in perl. Here is what I tried but failed.
my @in = ();
$n = $#ARGV + 1;
for ($i=0; $i < $n; $i++)
{
open($in[$i], "<" . $ARGV[$i]);
}
Thank you for your help.
r****t
发帖数: 10904
2
perl不知道,python一行就行:
fps = [open(fn) for fn in sys.argv[1:]]

look
failed.

【在 z*y 的大作中提到】
: I want to declare an array of file pointers. For example in C, it will look
: like: FILE *fp[n].
: However, I don't know how to do it in perl. Here is what I tried but failed.
: my @in = ();
: $n = $#ARGV + 1;
: for ($i=0; $i < $n; $i++)
: {
: open($in[$i], "<" . $ARGV[$i]);
: }
: Thank you for your help.

t****t
发帖数: 6806
3
how does it fail? this piece of code runs well on my system.
one thing you may want to know, if you put (the reference of) a filehandle
in an element of array, you may not use <...> to read a line from it. in
other word, or <$FH> works, but anything other than bareword or simple
scalar variable is interpreted as fileglob. if you have to use an array of (
the references of) filehandles, use readline(...) instead of <...>.

look
failed.

【在 z*y 的大作中提到】
: I want to declare an array of file pointers. For example in C, it will look
: like: FILE *fp[n].
: However, I don't know how to do it in perl. Here is what I tried but failed.
: my @in = ();
: $n = $#ARGV + 1;
: for ($i=0; $i < $n; $i++)
: {
: open($in[$i], "<" . $ARGV[$i]);
: }
: Thank you for your help.

1 (共1页)
进入Programming版参与讨论
相关主题
问C++文件路径的问题a simple question
请教C++问题Perl里面$,@,#等字符问题
新人,问个很弱的perl问题一道面试怪题C++. (转载)
C++ online Test 又一题 (转载)简单的perl问题
请看看这个Perl random sampling code 有什么问题,python gc question
Perl 6 改动很大很恶心perl question: can I have a key of hash to be
javascript问个基本 C array 问题
int *a [] 和int (*a)[] 一样吗一个nested class的问题
相关话题的讨论汇总
话题: perl话题: argv话题: file话题: array话题: question