Help with using glob() with stat()

Discussion in 'Perl' started by Tony, Jul 10, 2003.

  1. Tony

    Tony Guest

    Hello All,

    I'm having difficulty in using the glob function with stat.

    Here is a simple piece of code –
    -----------------------------------------------------------
    #! /usr/bin/perl -w
    use File::Glob;
    use File::stat;

    $loc_dir = "/home/tony/perlTest";

    my @fileList;
    my $modTime;
    my $filename;

    @fileList = glob ("$loc_dir/*.txt");
    $filename = $fileList[0];
    print "$filename\n";
    $modTime = (stat($filename))[9];
    print "$modTime\n";
    ----------------------------------------------------------------------------

    The $modeTime being returned by the stat() function I believe is
    returning a null, since I am not getting anything back..

    The print statements are returning:

    /home/tony/perlTest/test1.txt
    Use of uninitialized value in concatenation (.) or string at
    ../sample5.pl line 15.

    --------

    Correct me if I'm wrong, but I believe that the second statement "Use
    of..." is indicating that $modTime is being set to NULL.

    Any help would be appreciated.

    Tony
     
    Tony, Jul 10, 2003
    #1
    1. Advertising

  2. Tony

    Tony Guest

    Steve,

    Thanks - that worked like a charm....

    Tony


    Steve Grazzini <> wrote in message news:<l6iPa.27089$>...
    > Tony <> wrote:
    > > Here is a simple piece of code ?
    > > ----------------------------------------------------
    > > #! /usr/bin/perl -w
    > > use File::Glob;
    > > use File::stat;

    > ^^^^^^^^^^
    >
    > Here's your problem. The builtin stat() returns a big
    > list, but the version exported by File::stat returns an
    > object.
    >
    > > $loc_dir = "/home/tony/perlTest";
    > >
    > > my @fileList;
    > > my $modTime;
    > > my $filename;
    > >
    > > @fileList = glob ("$loc_dir/*.txt");
    > > $filename = $fileList[0];
    > > print "$filename\n";
    > > $modTime = (stat($filename))[9];

    >
    > So stat() returns a list of only one item (the object)
    > and you're looking for the tenth element of that list.
    >
    > Just get rid of the "use File::stat". For that matter
    > you could get rid of "use File::Glob" as well.
    >
    > > Correct me if I'm wrong, but I believe that the second
    > > statement "Use of..." is indicating that $modTime is
    > > being set to NULL.

    >
    > It's "undef" in Perl, but more or less the same idea.
    >
    > HTH
     
    Tony, Jul 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton
    Replies:
    3
    Views:
    9,764
    Pete Becker
    Jun 2, 2005
  2. Patrick Useldinger

    os.stat('<filename>')[stat.ST_INO] on Windows

    Patrick Useldinger, Feb 27, 2005, in forum: Python
    Replies:
    6
    Views:
    1,227
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Mar 3, 2005
  3. Magesh
    Replies:
    3
    Views:
    465
    Gordon Burditt
    Oct 5, 2007
  4. Rolf Krüger
    Replies:
    2
    Views:
    640
    Ian Collins
    Mar 12, 2008
  5. ruck
    Replies:
    10
    Views:
    1,298
Loading...

Share This Page