TIMTOWTDI, Robin.
Stat:
0 dev device number of filesystem
1 ino inode number
2 mode file mode (type and permissions)
3 nlink number of (hard) links to the file
4 uid numeric user ID of file's owner
5 gid numeric group ID of file's owner
6 rdev the device identifier (special files only)
7 size total size of file, in bytes
8 atime last access time in seconds since the epoch
9 mtime last modify time in seconds since the epoch
10 ctime inode change time in seconds since the epoch (*)
11 blksize preferred block size for file system I/O
12 blocks actual number of blocks allocated
8 being atime, 9 being mtime and 10 ctime.
[EMAIL PROTECTED] = Array
my$FIRSTTIME = Variable
Oh well. let me just use it in script
#!/usr/bin/perl -w
use strict;
use POSIX qw(setsid);
# set costants
my$MAKEPORT="/home/bin/make-port";
# daemonize the program
&daemonize;
while(1) {
# set costants
[EMAIL PROTECTED]("/home/std/std-unix-misc.tar.gz") ;
my$FIRSTTIME = "$FILETIME[9]";
my$SECTIME=scalar time;
sleep(2);
if (($FIRSTTIME + 2) > $SECTIME) {
system($MAKEPORT);
}}
sub daemonize {
my $outlog = '/home/bin/daemons/logs/hotfolder_out.log';
my $errorlog = '/home/bin/daemons/logs/hotfolder_error.log';
chdir '/' or die "Can't chdir to /: $!";
umask 0;
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, ">$outlog" or die "Can't write to /dev/null: $!";
open STDERR, ">$errorlog" or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Robin Norwood
Sent: Monday, July 07, 2003 7:13 AM
To: [EMAIL PROTECTED]
Cc: SPENCERS
Subject: Re: Stat() - Getting one element
"SPENCERS" <[EMAIL PROTECTED]> writes:
> Or.
>
> [EMAIL PROTECTED]("filename") ;
> my$FIRSTTIME = "$FILETIME[8,9,10]";
>
> -----Original Message-----
> From: Paul Kraus [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 07, 2003 6:27 AM
> To: [EMAIL PROTECTED]
> Subject: Stat() - Getting one element
>
>
> What's an easy way to grab just one element out of a function that
> returns a list.
>
> For instance if I was to stat a file and all I wanted was the $atime or
> if I just wanted the three timestamps atime mtime and ctime. Thanks.
my $atime = (stat("filename"))[8];
The outer parens force list context, which you can then take the 9th
element of. (atime)
You can also do -
my @times = (stat("filename"))[8 .. 10];
And, just for fun:
my $times = { }; # empty hashref
@{$times}{qw/atime mtime ctime/} = # a slice of the hashref...
(stat("filename"))[8 .. 10]; # to which we map some of the fields of
stat()
print $times->{mtime}; # should yield the same as (stat("filename"))[9]
Don't worry if the last snippet of code doesn't make any sense to you
- it doesn't make any sense to me either. :-)
-RN
--
Robin Norwood
Red Hat, Inc.
"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]