By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

PERL: Trying to get the unix timestamp using File::stat.

P: 1
Greetings all, great forum, this is my first post.

Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have written a short script that should iterate through all files in the current directory and output unix epoch time. The script in it's entirety is posted below:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  3. use warnings;
  4. use strict;
  5. use Cwd;
  6. use File::Find;
  7. use File::Path;
  8. use File::stat;
  9. use Time::Local;
  11.         my $sourceDir = getcwd;
  13.         opendir DIR, $sourceDir or die "cannot open dir $sourceDir: $!";
  14.         print "Source Dir: $sourceDir\n";
  15.         my @file = readdir DIR;
  16.         closedir DIR;
  17.         print "Attempting to read files.\n\n";
  18.         chdir($sourceDir);
  20.    foreach my $file (@file)
  21.    {
  22.         print "file in loop: $file.\n";
  23.         my $unixT = (stat($file))[9];
  24.         print "Attempting to print stat: $unixT \n";
  25.    }
BTW, thanks in advance :)
Jan 9 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,059
What does your script do when you run it?
Jan 9 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.