#!/usr/bin/perl -w
#
# $Revision: 1.2 $ $Date: 2012-07-26 17:11:48-04 $
# $Source: /home/vogelke/bin/RCS/ls2touch,v $
# $Host: sys7.com $
# $UUID: 6ec257b1-330f-373e-b690-a6f4eb3284e0 $
#
#<ls2touch: create touch commands to set modtime of arguments.
# example: ls2touch a*
# example: find . -depth -print | xargs ls2touch

use strict;
use subs qw/modtime/;

my $file;
my $str;

foreach $file (@ARGV) {
    $file =~ s!/$!!;
    $str = modtime($file);
    print "touch -d '$str' $file\n";
}

exit(0);

# -------------------------------------------------------------------
sub modtime {
    my ($path) = @_;
    my $mt = (stat($path))[9];
    my ($sec, $min, $hour, $mday, $mon, $year) = localtime($mt);

    return sprintf("%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d",
        $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
}
