Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.09 KB | None | 0 0
  1. use POSIX qw(strftime);
  2.  
  3. my $a0 =  $ARGV[0];
  4. my $a1 =  $ARGV[1];
  5. my $a2 =  $ARGV[2];
  6.  
  7. if ($a0 eq "time") {
  8.  
  9.   if($#ARGV != 2) {
  10.     print STDERR "usage: cirba-stat.pl - time arguments always require a total of 3 arguments\n";
  11.     exit 1;
  12.   }
  13.   if(!defined($ARGV[2])) {
  14.     $a2 = "ctime";
  15.   }
  16.  
  17.   if($a2 eq "ctime") {
  18.     if($a1 eq "now") {
  19.       print time()."\n";
  20.     } else {
  21.       print $a1."\n";
  22.     }
  23.   } else {
  24.     if($a1 eq "now") {
  25.       print strftime($a2,localtime(time()))."\n";
  26.     } else {
  27.       print strftime($a2,localtime($a1))."\n";
  28.     }
  29.   }
  30. } elsif($a0 eq "stat") {
  31.  
  32.   if($#ARGV < 1) {
  33.     print STDERR "usage: cirba-stat.pl - stat arguments always require a total of 2 arguments\n";
  34.     exit 1;
  35.   }
  36.  
  37.   my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($a1);
  38.   if(!defined($ARGV[2])) {
  39.     $a2 = "%a %b %e %T %Y";
  40.   }
  41.  
  42.   if($a2 eq "ctime") {
  43.     print $mtime."\n";
  44.   } else {
  45.     print strftime($a2,localtime($mtime))."\n";
  46.   }
  47.  
  48. }
  49.  
  50.  # print time();
  51.  # $timeStr = strftime($a2,localtime($a1));
  52.  
  53. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement