今天看到一段代码 虽然知道运行结果 但是不明白里面的原理
$SEEK = "123.txt";
open(SEEK);
while(<SEEK>){
print;
}
close SEEK;
open(SEEK) 里面省略了什么? 怎么把"123.txt"带进去的
churchmice 回复于:2008-03-10 18:45:31
你确认是SEEK而不是$SEEK ??
hitsubunnu 回复于:2008-03-10 18:46:55
不是 你可以运行一下 就是因为这个 我才不理解呢
churchmice 回复于:2008-03-10 18:49:36
果然神奇
see
perldoc -f open
open FILEHANDLE,EXPR
open FILEHANDLE,MODE,EXPR
open FILEHANDLE,MODE,EXPR,LIST
open FILEHANDLE,MODE,REFERENCE
open FILEHANDLE
Opens the file whose filename is given by EXPR, and associates
it with FILEHANDLE.
(The following is a comprehensive reference to open(): for a
gentler introduction you may consider perlopentut.)
If FILEHANDLE is an undefined scalar variable (or array or hash
element) the variable is assigned a reference to a new anony-
mous filehandle, otherwise if FILEHANDLE is an expression, its
value is used as the name of the real filehandle wanted. (This
is considered a symbolic reference, so "use strict 'refs'"
should not be in effect.)
引用: If EXPR is omitted, the scalar variable of the same name as the
FILEHANDLE contains the filename. (Note that lexical vari-
ables--those declared with "my"--will not work for this pur-
pose; so if you're using "my", specify EXPR in your call to
open.)
就是说open(FILEHANDLE)相当与
open(FILEHANDLE,$FILEHANDLE);
[ 本帖最后由 churchmice 于 2008-3-10 18:51 编辑 ]
hitsubunnu 回复于:2008-03-10 19:03:45
perl 有点儿太自由了
我就因为这个 改了将近4个小时的程序 让我在将近2000行代码中 就找打开文件的位置
这么写程序 有些害人
在此对之前写程序的人亲属表示抱歉
churchmice 回复于:2008-03-10 19:14:07
引用:原帖由 hitsubunnu 于 2008-3-10 19:03 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8061270&ptid=1063349]
perl 有点儿太自由了
我就因为这个 改了将近4个小时的程序 让我在将近2000行代码中 就找打开文件的位置
这么写程序 有些害人
在此对之前写程序的人亲属表示抱歉
习惯了就好了
start2008 回复于:2008-03-10 21:38:04
呵呵 懒惰是perler的美德
正在看的learning perl中提到的
又学了一招 :mrgreen:
perljoker 回复于:2008-03-11 09:52:35
:shock:
我倒,这招学了可不好……
cobrawgl 回复于:2008-03-11 10:37:06
perl 给你自由
但自由是有代价的
|