2005-04-14

 

[Perl] A 'stat' replacement

I discovered Planet MySQL recently, and saw an a very good Perl solution that can serve as a stat(1) replacement.

The code:

1 #!/usr/bin/perl
2 use POSIX qw(strftime);
3
4 my $FORMAT="%H:%M %a, %e %b %y";
5
6 foreach(@ARGV)
7 {
8 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
9 $atime,$mtime,$ctime,$blksize,$blocks)
10 = stat($_);
11 print $_."\n";
12 print "Dev: $dev\n";
13 print "inode: $ino\n";
14 print "mode: $mode\n";
15 print "nlink: $nlink\n";
16 print "uid: $uid\n";
17 print "gid: $gid\n";
18 print "rdev: $rdev\n";
19 print "size: $size\n";
20 print "atime: ".strftime($FORMAT,localtime($atime))."\n";
21 print "mtime: ".strftime($FORMAT,localtime($mtime))."\n";
22 print "ctime: ".strftime($FORMAT,localtime($ctime))."\n";
23 print "blksz: $blksize\n";
24 print "blks: $blocks\n\n";
25 }
26

Thanks Stewart Smith for the effort...

Enjoy :)

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?