5 # for each filename on the command line
7 # make a backup of the file
8 # - error if there is already a backup?
9 # flush the live version(?)
10 # start a line-by-line copy of the backup to the new file,
11 # doing the BeginDate/EndDate substitution
13 # <!-- #BeginDate format:En1m -->3-oct-11 18:20<!-- #EndDate -->
14 # <!-- #BeginDate format:En2m -->01-Aug-2011 17:56<!-- #EndDate -->
15 # without the 'm' no minutes are included.
20 my @m_abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
24 $mod_time = (stat ($i))[9];
25 $stamp = localtime($mod_time);
26 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
30 # print "<$i> at <$stamp>\n";
32 open(my $IFILE, "<", $i) or die "Cannot open < $i: $!";
33 open(my $OFILE, ">", $i.".new") or die "Cannot open > $i.new: $!";
35 if (/(.*<!--\s*#BeginDate\s*format:)(\S*)(\s*-->).*(<!--\s*#EndDate\s*-->.*)/) {
37 # print "as: <$1><$2><$3>...<$4>\n";
38 print { $OFILE } $1,$2,$3;
39 printf { $OFILE } "%s-%s-%s %02d:%02d", $mday,$m_abbr[$mon],$year,$hour,$min;
40 print { $OFILE } $4,"\n";
49 utime(time, $mod_time, "$i.new") || die "touch $i.new failed: $!";
51 rename $i,"$i.old" || die "rename $i,$i.old failed: $!";
52 rename "$i.new",$i || die "rename $i.new,$i failed: $!";