[ale] perl File::stat question
David S. Jackson
deepbsd at earthlink.net
Mon Feb 4 10:44:17 EST 2002
I'm trying to stat a file
$info = stat($file);
and then set
$accesslast = $info->atime;
and
$created = $info->mtime;
For some reason, stat($file) seems to be coming up null. When I
substitute another file, say stat("/etc/passwd"), $accesslast and
$created come up fine. Can you let me know what I'm doing wrong?
NOTE: I don't normally include the whole damn script, but if
there's anything *else* wrong with the code, please let me know
about that too, okay? I'm new at this stuff and I can always use
good advice! :-)
########### SNIP #############
#!/usr/bin/perl -wT
use Carp;
use CGI qw(:standard);
use File::stat;
use strict;
my $directory = '/var/www/compedge';
my $url = 'http://sylvester.dsj.net';
my $dir = 'compedge';
print header(), start_html("My ComputorEdge Articles"),
h1("Articles from <i>I Don't Do Windows</i>: ");
print p( a({href=>"http://www.computoredge.com"}, "ComputorEdge
Magazine") . " has been gracious enough to give me and my
interest in Linux and UNIX some space in their magazine. Over
the months and years, my articles have accumulated to be a rather
regular part of the magazine. Hopefully, they can be of help for
anyone new to the free UNIXex. They are listed for your benefit
below.");
print p("Please feel free to search for stuff in my articles " .
a({href=>"$url/$dir/search.html"}, "here"). " Note: I really
need to clean this script up! It's one of Matt's archive scripts
that can't pass muster with use strict or the -T switch. :-)");
print p("Meanwhile, you can simply " .
a({href=>"http://www.dsj.net/compedge/"}, "click here ") . "and
browse the directory of articles yourself. Find whatever seems
interesting to you.");
# Start printing the table
print "<table align=center border=1>\n";
print th( "Files:"), th( "Created:"), th("Last Accessed:");
opendir (DIR,"$directory");
while (my $file = readdir(DIR)) {
if ($file =~ /\.html$/) {
open(FILE,"$directory/$file");
while (<FILE>) {
chomp;
(my $line) = $_;
if ($line =~ /<title>/i) {
# only catches titles on one line...fix later...
(my $title = $line) =~ s#(<title>)(.*)(</title>)#$2#i;
my $info = stat($file);
my $created = $info->mtime;
my $accesslast = $info->atime;
print Tr( td( a({href=>"$dir/$file"}, "<b>$title</b>")),
td( "Created: $created"), td("Accessed last: $accesslast"));
next;
}
}
close FILE;
}
}
# close up the table
print "</table>\n";
close DIR;
print end_html();
############### SNIP ##################
TIA!
--
David S. Jackson http://www.dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
It's easy to get on the internet and forget you have a life
-- Topic on #LinuxGER
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list