From owner-freebsd-questions Mon Feb 4 7:45:31 2002 Delivered-To: freebsd-questions@freebsd.org Received: from harrier.prod.itd.earthlink.net (harrier.mail.pas.earthlink.net [207.217.120.12]) by hub.freebsd.org (Postfix) with ESMTP id EF16C37B430 for ; Mon, 4 Feb 2002 07:45:18 -0800 (PST) Received: from user-119a2km.biz.mindspring.com ([66.149.10.150] helo=sylvester.dsj.net) by harrier.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16XlIw-0001cm-00; Mon, 04 Feb 2002 07:45:14 -0800 Received: (from dsj@localhost) by sylvester.dsj.net (8.9.3/8.9.3/Debian 8.9.3-21) id KAA17322; Mon, 4 Feb 2002 10:44:17 -0500 Date: Mon, 4 Feb 2002 10:44:17 -0500 From: "David S. Jackson" To: ale@ale.org, kplug-list@kernel-panic.org, freebsd-questions@freebsd.org Subject: perl File::stat question Message-ID: <20020204104417.A17219@sylvester.dsj.net> Reply-To: "David S. Jackson" Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 Don't Do Windows: "); 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 "\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 () { chomp; (my $line) = $_; if ($line =~ //i) { # only catches titles on one line...fix later... (my $title = $line) =~ s#(<title>)(.*)()#$2#i; my $info = stat($file); my $created = $info->mtime; my $accesslast = $info->atime; print Tr( td( a({href=>"$dir/$file"}, "$title")), td( "Created: $created"), td("Accessed last: $accesslast")); next; } } close FILE; } } # close up the table print "
\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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message