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