Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #201459

Re: perl; Trying to get File::stat to work

From Bob McGowan <ramjr0915@gmail.com>
Newsgroups linux.debian.user
Subject Re: perl; Trying to get File::stat to work
Date 2018-10-20 05:50 +0200
Message-ID <wKQqZ-2Lu-1@gated-at.bofh.it> (permalink)
References <wKPuV-2dg-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

It looks like this has to do with mixing the usage of the "native" stat 
of Perl with the "object" version from File::stat.

The 'stat' from File::stat returns a reference to an object, which has 
the stuff you're wanting, tucked away internally as object variables.  
You need to do:

     use File::stat;

     $statRef = stat('testfile');

     $mtime = $statRef->mtime ()

Hoping this helps.

Bob

On 10/19/18 7:47 PM, Martin McCormick wrote:
> I am a member of a perl discussion list but it seems to have gone
> away so I hope somebody here can give me an idea as to why the
> stat function is not working.
>
> 	Create a file called testfile in your working directory
> and then run the following perl script:
>
> #!/usr/bin/perl -w
> use strict;
> use warnings::unused;
> use File::stat;
> use File::Spec;
>
> my $last_update_time;
>
> $last_update_time = ( stat("testfile") )[9];
> printf("%d\n",$last_update_time);
>
> 	As this stands, it should print a 10 or so digit number
> representing the number of seconds since Midnight UTC on January
> 1 of 1970.  What it actually does is to not set the variable and
> you get the "Use of uninitialized variable" squawk with no
> value assignment to the variable.
>
> 	The [9] referrs to the ninth element in an array which
> should be the time stamp.
>
> Thanks for any suggestions.
>
> 	Martin McCormick WB5AGZ
>

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

perl; Trying to get File::stat to work "Martin McCormick" <martin.m@suddenlink.net> - 2018-10-20 04:50 +0200
  Re: perl; Trying to get File::stat to work Bob McGowan <ramjr0915@gmail.com> - 2018-10-20 05:50 +0200
    Re: perl; Trying to get File::stat to work "Martin McCormick" <martin.m@suddenlink.net> - 2018-10-20 14:30 +0200
  Re: perl; Trying to get File::stat to work Dave Sherohman <dave@sherohman.org> - 2018-10-20 10:20 +0200
  Re: perl; Trying to get File::stat to work David Christensen <dpchrist@holgerdanske.com> - 2018-10-21 06:40 +0200

csiph-web