Can a Perl script modify itself?

前端 未结 6 1475
旧巷少年郎
旧巷少年郎 2020-12-31 10:48

I would like to have my scripts keep track of thier last date of revision internally as a comment. Is this possible? It seems to me that it would need to grab the date and

6条回答
  •  天命终不由人
    2020-12-31 11:41

    #! /usr/bin/env perl
    use warnings;
    use strict;
    use autodie;
    
    {
      open my $self, '>>', $0;
      my $time = localtime;
      print {$self} "# ran on $time\n";
    }
    
    __END__
    # ran on Wed Aug 25 16:41:05 2010
    

提交回复
热议问题