LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-27-2012, 05:02 AM   #1
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Fedora 16 / Ubuntu 11.10 / CentOS 6.2
Posts: 358

Rep: Reputation: 60
Perl: Get file modified date without using stat


The stat.pm module in several server Perl installations appears to be broken with this error, although it works elsewhere: -

Use of uninitialized value in stat at /usr/lib/perl5/5.8.8/File/stat.pm line 49.

Is there a way of getting a file's modified date without using stat?
 
Old 01-27-2012, 05:21 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,048

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
You can always use a system call ... in regard to the error, I'd guess that you may be sending it unsanitised data.
 
1 members found this post helpful.
Old 01-27-2012, 05:25 AM   #3
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Fedora 16 / Ubuntu 11.10 / CentOS 6.2
Posts: 358

Original Poster
Rep: Reputation: 60
Where is the unsanitised data here?

Code:
$file = "/path/to/some/file";
$file_handle = IO::File->new($file,'r');
$dttm_raw_modified = stat($file_handle)->mtime;
If I can't fix this, how do I do a system call?
 
Old 01-27-2012, 05:44 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,048

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
When I say unsanitised I mean that there may be strange characters or spaces or the file may not exist or may be a relative path that's not correct from your scripts working directory. Basically the data may not be accurate.

You can use system() to call any executable in the system, for example:
Code:
system("stat $filename")
 
1 members found this post helpful.
Old 01-27-2012, 06:10 AM   #5
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian
Posts: 401

Rep: Reputation: 187Reputation: 187
Hi.

You will get that error if $file does not exists.
Try this:
Code:
use IO;
use File::stat;

$file = "/path/to/some/file";
$file_handle = IO::File->new($file,'r') or die "No $file: $!";
$dttm_raw_modified = stat($file_handle)->mtime;
print $dttm_raw_modified;
 
1 members found this post helpful.
Old 01-27-2012, 07:04 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 241Reputation: 241Reputation: 241
Or without file handle
Code:
#!/usr/bin/perl

use File::stat;

$file = '/path/to/some/file';
$st = stat($file) or die "No $file: $!";

$dttm_raw_modified = $st->mtime;
print $dttm_raw_modified;
 
1 members found this post helpful.
Old 01-27-2012, 07:09 AM   #7
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Fedora 16 / Ubuntu 11.10 / CentOS 6.2
Posts: 358

Original Poster
Rep: Reputation: 60
Ah, got it - misleading error making me think it was a problem with stat.pm, when it's actually a null file handle. Cheers
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cat file with its modified date n time coolplanet Programming 7 10-25-2009 08:44 PM
struct stat for a file , how can it be modified linuxdoniv Programming 1 08-05-2008 08:02 AM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
[bash] Seeing if a file has been modified before/after a date w3stfa11 Programming 7 10-15-2006 06:02 PM
Where can I look for the config file for modified date and time ForumKid Linux - General 1 09-19-2003 08:05 AM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration