RE: Stat() - Getting one element

2003-07-07 Thread SPENCERS
TIMTOWTDI, Robin.

Stat:

 0 dev  device number of filesystem
 1 ino  inode number
 2 mode file mode  (type and permissions)
 3 nlinknumber 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 atimelast access time in seconds since the epoch
 9 mtimelast modify time in seconds since the epoch
10 ctimeinode 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;
setsidor 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]



RE: Stat() - Getting one element

2003-07-07 Thread SPENCERS
Paul.

   Stat is a Operator and not function and the operand to stat is a
filehandle, or an expression that evalutes to a filename. As the old rule
says "If you use the parentheses, the simple (but occasionally surprising)
rule is this: It LOOKS like a function, therefore it IS a function, and
precedence doesn't matter. Otherwise it's a list operator or unary operator,
and precedence does matter.

Hope this makes sense.

-Original Message-
From: Paul Kraus [mailto:[EMAIL PROTECTED]
Sent: Monday, July 07, 2003 6:52 AM
To: 'Jenda Krynicky'; [EMAIL PROTECTED]
Subject: RE: Stat() - Getting one element


Ok I understand this but why the need for enclosing the function call in
().

Thanks for the info.

Paul

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]
Sent: Monday, July 07, 2003 9:38 AM
To: [EMAIL PROTECTED]
Subject: Re: Stat() - Getting one element


From: "Paul Kraus" <[EMAIL PROTECTED]>
> 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.

$atime = (stat($file))[8];

($atime, $mtime, $ctime) = (stat($file))[8,9,10];

HTH, Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
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]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Stat() - Getting one element

2003-07-07 Thread Rob Dixon
Paul Kraus wrote:
> From: Jenda Krynicky [mailto:[EMAIL PROTECTED]
> > From: "Paul Kraus" <[EMAIL PROTECTED]>
> > 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.
>
> $atime = (stat($file))[8];
>
> ($atime, $mtime, $ctime) = (stat($file))[8,9,10];
>
> Ok I understand this but why the need for enclosing the function call in
> ().
>

You've been told that it's to force list context, which isn't strictly true.

 () = stat($file)

forces list context, but

 () = stat($file)[8..10]

doesn't work. The extra parentheses are there to avoid ambiguity (in
practice, to resolve a syntax error). The subscription has equal
priority to the 'stat' operator, so you could be meaning either the
8th, 9th and 10th elements of the call to 'stat' (which you do) or
the result of 'stat' applied to the 8th, 9th and 10th elements of
the list ($file) (which you don't). That would look like this

 () = stat(($file)[8,9,10]);

and return an empty list.


It's easier to think of with a list operator which returns a list:

  my @a = (reverse ('w', 'x', 'y', 'z'))[0,1];

is fine, and assigns ('z', 'y')

  my @a = reverse (('w', 'x', 'y', 'z')[0,1]);

is also fine, and assigns ('x', 'w'). But

  my @a = reverse ('w', 'x', 'y', 'z')[0,1];

is ambiguous, and dies with a syntax error.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Stat() - Getting one element

2003-07-07 Thread Janek Schleicher
Paul Kraus wrote at Mon, 07 Jul 2003 09:27:15 -0400:

> 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.

A completely different way that works in the special case of stat, would be

my ($atime, $mtime, $ctime) = (-A $file, -M _, -C _);

That also only calls once the stat function, but is a bit more intuitiv,
as indexing them with [8,9,10] from the stat returning list.

Read perldoc perlvar for details.


Greetings,
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Stat() - Getting one element

2003-07-07 Thread Robin Norwood
"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]



RE: Stat() - Getting one element

2003-07-07 Thread Paul Kraus
Ok I understand this but why the need for enclosing the function call in
().

Thanks for the info.

Paul

-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 07, 2003 9:38 AM
To: [EMAIL PROTECTED]
Subject: Re: Stat() - Getting one element


From: "Paul Kraus" <[EMAIL PROTECTED]>
> 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.

$atime = (stat($file))[8];

($atime, $mtime, $ctime) = (stat($file))[8,9,10];

HTH, Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
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]



RE: Stat() - Getting one element

2003-07-07 Thread SPENCERS
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.

Paul Kraus


-- 
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]



Re: Stat() - Getting one element

2003-07-07 Thread Jenda Krynicky
From: "Paul Kraus" <[EMAIL PROTECTED]>
> 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.

$atime = (stat($file))[8];

($atime, $mtime, $ctime) = (stat($file))[8,9,10];

HTH, Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Stat() - Getting one element

2003-07-07 Thread Sudarshan Raghavan


Paul Kraus wrote:

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, $mtime, $ctime) = (stat ($your_file))[8, 9, 10];

Paul Kraus

 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Stat() - Getting one element

2003-07-07 Thread Paul Kraus
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.

Paul Kraus


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]