Can a Perl script modify itself?

前端 未结 6 1486
旧巷少年郎
旧巷少年郎 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:48

    The following worked on a FreeBSD system. It appends to the end, which sounds acceptable to you, but doesn't conform to the "normal" way of documenting changes within a file - at least for me, as I've almost always seen it done at the beginning. You'll probably want to change the way the date/time is displayed.

    #!/usr/bin/perl -w
    open SELF, ">> selfModify.pl" or die "Unable to open self";
    print SELF "# ran/modified at " . join(' ', localtime()) . "\n";
    close(SELF);
    

    Whether this is wise or not I'll leave for you to decide.

提交回复
热议问题