小骆驼 9.5.3节例子运行问题

小骆驼 9.5.3节例子运行问题

小骆驼9.5.3节有个例子,我编辑了fred03.dat文件
    Program name: granite
    Author: Gilbert Bates
    Company: RockSoft
    Department: R&D
    Phone: +1 503 555-0095
    Date: Tues March 9, 2004

    Version: 2.1
    Size: 21k
    Status: Final beta

编辑t9.pl文件
#!/usr/bin/perl -w

    use strict;

    chomp(my $date = `date`);
    $^I = ".bak";

    while (<>) {
      s/^Author:.*/Author: Randal L. Schwartz/;
      s/^Phone:.*\n//;
      s/^Date:.*/Date: $date/;
      print;
    }

然后#./t9.pl fred03.dat

运行后无任何输出,fred03.dat.bak文件倒是创建了,但是Author: ,Date,Phone都没有修改,请问是什么原因。
sh-3.2# ls data*
data
sh-3.2# cat data
root

sh-3.2# cat a.pl
#!/usr/bin/perl

use strict;

$^I = ".baK";

while(<>) {
    s/root/toor/;
    print;
}
sh-3.2# perl a.pl data
sh-3.2# ls data*
data  data.baK
sh-3.2# cat data
toor

sh-3.2# cat data.baK
root

[root@as4server test_script]# cat fred03.dat
Program name: granite
Author: Gilbert Bates
Company: RockSoft
Department: R&D
Phone: +1 503 555-0095
Date: Tues March 9, 2004
Version: 2.1
Size: 21k
Status: Final beta

[root@as4server test_script]# cat test47
#!/usr/bin/perl -w

use strict;

chomp (my $date = `date`);
$^I = ".bak";

while (<>;){
        s/^Author:.*/Author: Randa1 L. Schwartz/;
        s/^Phone:.*\n//;
        s/^Date:.*/Date: $date/;
        print;
}

[root@as4server test_script]# perl test47 fred03.dat
[root@as4server test_script]# cat fred03.dat
Program name: granite
Author: Randa1 L. Schwartz
Company: RockSoft
Department: R&D
Date: Wed Apr  9 11:21:26 CST 2008
Version: 2.1
Size: 21k
Status: Final beta

按你的输入进去 我的可以修改啊 是不是你写漏了什么 详细的检查多几次吧!

没有漏写,刚刚用root用户试了一下可以了。但是我之前用oracle用户不可以,文件owner是oracle的,奇怪

[oracle@ho perl]$ ll fred03.dat
-rw-r--r--  1 oracle oinstall 160 Apr  9 15:07 fred03.dat
我是再windows下测试的好像没反映  我再bin目录下建了个fred03.dat  然后就再cmd下运行
C:\usr\perl\bin>perl t9.pl fred03.dat   就一直没反映 什么原因呢???


QUOTE:
原帖由 wuyue1106 于 2008-4-9 21:31 发表
我是再windows下测试的好像没反映  我再bin目录下建了个fred03.dat  然后就再cmd下运行
C:\usr\perl\bin>perl t9.pl fred03.dat   就一直没反映 什么原因呢???

try change
  chomp ( my $date = `date` );
to
chomp ( my $date = `date /T` );

C:\>date /?
Displays or sets the date.

DATE [/T | date]

Type DATE without parameters to display the current date setting and
a prompt for a new one.  Press ENTER to keep the same date.

If Command Extensions are enabled the DATE command supports
the /T switch which tells the command to just output the
current date, without prompting for a new date.

C:\>date /t
2008/04/10 星期四