Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Help with using glob() with stat()

Reply
Thread Tools

Help with using glob() with stat()

 
 
Tony
Guest
Posts: n/a
 
      07-10-2003
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
 
Reply With Quote
 
 
 
 
Tony
Guest
Posts: n/a
 
      07-11-2003
Steve,

Thanks - that worked like a charm....

Tony


Steve Grazzini <(E-Mail Removed)> wrote in message news:<l6iPa.27089$(E-Mail Removed)>.. .
> Tony <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why doesn't this "belongs_to" line of code, using options override,not work??? (need help using belongs_to with options) Greg Hauptmann Ruby 1 10-30-2008 10:44 PM
Help Help Help Pentax S5i Help needed (Please) The Martian Digital Photography 14 06-20-2008 07:56 AM
Help! Cannot login using IE but can using FF hplayer03 ASP .Net 3 08-17-2007 03:33 PM
HELP!!HELP!! - Import XMl into SQl using ASp Michael Persaud ASP .Net Building Controls 3 08-17-2004 06:09 PM
HELP! HELP! HELP! Opening Web Application Project Error =?Utf-8?B?dHJlbGxvdzQyMg==?= ASP .Net 0 02-20-2004 05:16 PM



Advertisments