Forum Moderators: coopster & phranque

Message Too Old, No Replies

Reading 'last_modified' with Filehandles

Surely this is possible.

         

molecularr

6:08 pm on Aug 30, 2004 (gmt 0)

10+ Year Member



Hello,

I apologize in advance for still being such a newbie at Perl, but I need to write something so that a filehandle reads and prints an identified file, but it also prints the last_modified date for the file being read.

I'm just not sure how filehandles process the data, but I'm sure this is an easy thing to do.

Here's my example code in question (where the question marks = the part I can't figure out):


open( READ, "$file_to_print");
@array=<READ>;
close(READ);
print "File: $file_to_print\n\n";
print "Last updated:?";
foreach $line(@array){
print <<HTML;
$line
HTML
}

Can anyone help me out?

Many thanks.

tombola

7:52 pm on Aug 30, 2004 (gmt 0)

10+ Year Member



The stat-function returns a 13-element list containing the status info for a file.
Note that not all filesystem types support all these fields...

($device_number, $inode_number, $file_mode, $number_of_links, $user_id, $group_id, $device_id, $file_size, $last_access, $last_modified, $inode_change_time, $block_size, $blocks) = stat($file_to_print);

print "Last updated: $last_modified";

molecularr

4:55 am on Aug 31, 2004 (gmt 0)

10+ Year Member



Awesome. That was it.

Thanks!