相关疑难解决方法(0)

Perl脚本可以修改自己吗?

我想让我的脚本在内部跟踪他们的最后修订日期作为评论.这可能吗?在我看来,它需要获取日期,然后打开其脚本文件的附加,写入数据并保存文件.

感谢Everone,很棒的回答者.基于GreenMatt留下的代码片段,我把它扔到了一起......

#!/usr/bin/perl -w 

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;
$year += 1900;
$mon +=1;

open SELF, ">> letterhome.pl" or die "Unable to open self"; 
#print SELF "# ran/modified at " . join(' ', localtime(time)) . "\n"; 
print SELF "# ran/modified at $hour:$min:$sec on $mon/$mday/$year.\n"; 
close(SELF); 

# ran/modified at 31 48 23 24 7 110 2 235 1  
# unformated result of using localtime(time)  

#Results using formated time/date 
# ran/modified at 0:1:43 on 8/25/2010.
# ran/modified at 0:2:40 on 8/25/2010.
# …
Run Code Online (Sandbox Code Playgroud)

perl

11
推荐指数
2
解决办法
1898
查看次数

我们在Perl中有autochomp吗?

这是我的Perl代码用于监视Unix文件夹的样子:

#!/usr/bin/perl
use strict;
use warnings;
use File::Spec::Functions;

my $date    = `date`; chomp $date;
my $datef   = `date +%Y%m%d%H%M.%S`; chomp $datef;
my $pwd     = `pwd`; chomp $pwd;

my $cache   = catfile($pwd, "cache");
my $monitor = catfile($pwd, "monme");
my $subject = '...';
my $msg     = "...";
my $sendto  = '...';
my $owner   = '...';

sub touchandmail {
     `touch $cache -t "$datef"`;
     `echo "$msg" | mail -s "$subject" $owner -c $sendto`;
}

while(1) {

    $date  = `date`; chomp $date;
    $datef …
Run Code Online (Sandbox Code Playgroud)

string perl chomp

8
推荐指数
3
解决办法
1311
查看次数

标签 统计

perl ×2

chomp ×1

string ×1