avatar
z*y
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], "}
Thank you for your help.
avatar
r*t
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], ": }
: Thank you for your help.

avatar
t*t
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 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], ": }
: Thank you for your help.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。