File: touch.pl

package info (click to toggle)
ps-watcher 1.08-11.1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 772 kB
  • sloc: sh: 2,907; perl: 1,281; makefile: 104
file content (42 lines) | stat: -rwxr-xr-x 1,405 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w
my $vcid='$Id: touch.pl,v 1.4 2006/03/08 19:22:41 rockyb Exp $ ';
#  Copyright (C) 1997-2006  R. Bernstein email: rocky@cpan.org
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
use strict;
use File::Basename;
my $program = basename($0); # Who am I today, anyway? 

if (@ARGV != 1) {
  print "
usage:
  $program *file*

  A perl implimentation of a minimal Unix touch command: creates file *file*
  if it does not exist. In either case, the file is given a creation 
  time of the current time.
";
  exit 100;
}

print "$ARGV[0]\n";
if (-e $ARGV[0]) {
  my $now = time();
  my $count = utime $now, $now, $ARGV[0];
  exit ($count != 1);
} else {
  open(FILE, ">$ARGV[0]") || die "Can't open $ARGV[0]: $!";
  close(FILE);
  exit $?;
}