Help with using glob() with stat()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony

    Help with using glob() with stat()

    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

    #2
    Re: Help with using glob() with stat()

    Steve,

    Thanks - that worked like a charm....

    Tony


    Steve Grazzini <grazz@pobox.co m> wrote in message news:<l6iPa.270 89$Ha.25406@nwr dny02.gnilink.n et>...[color=blue]
    > Tony <melaragno@ssdd .nrl.navy.mil> wrote:[color=green]
    > > Here is a simple piece of code ?
    > > ----------------------------------------------------
    > > #! /usr/bin/perl -w
    > > use File::Glob;
    > > use File::stat;[/color]
    > ^^^^^^^^^^
    >
    > Here's your problem. The builtin stat() returns a big
    > list, but the version exported by File::stat returns an
    > object.
    >[color=green]
    > > $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];[/color]
    >
    > 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.
    >[color=green]
    > > Correct me if I'm wrong, but I believe that the second
    > > statement "Use of..." is indicating that $modTime is
    > > being set to NULL.[/color]
    >
    > It's "undef" in Perl, but more or less the same idea.
    >
    > HTH[/color]

    Comment

    Working...