473,609 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 19 '05 #1
1 7517
Steve,

Thanks - that worked like a charm....

Tony
Steve Grazzini <gr***@pobox.co m> wrote in message news:<l6******* ***********@nwr dny02.gnilink.n et>...
Tony <me*******@ssdd .nrl.navy.mil> 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

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2566
by: pancho | last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO on a Solaris 8 box - this module is needed to host some existing sites I will be migrating Note. I built PHP4 from source and it loads without an error. When I try t run "apachectl configtest" I get the following error: -- Cannot load /usr/local/apache/libexec/libphp3.so into server: ld.so.1: /usr/local/apache/bin/httpd: fatal: relocation error: file...
15
3077
by: Georgy Pruss | last post by:
On Windows XP glob.glob doesn't work properly for files without extensions. E.g. C:\Temp contains 4 files: 2 with extensions, 2 without. C:\Temp>dir /b * aaaaa.aaa bbbbb.bbb ccccc ddddd C:\Temp>dir /b *.
0
2015
by: Richard Taylor | last post by:
User-Agent: OSXnews 2.07 Xref: number1.nntp.dca.giganews.com comp.lang.python:437315 Hi I am trying to use py2app (http://undefined.org/python/) to package a gnome-python application called gramps (http://www.gramps-project.org) for MAC OS X.
3
5320
by: Spartan815 | last post by:
I am writing a program that does a command line search for a specified file, or to match a pattern (i.e. search for *.h). Once it finds the file(s) it has to output absolute pathname, size, owner id, group id, file permissions, time of last read, time of last write, time of last change. I have a few questions that if anyone could answer I would be greatly appreciative. Below is my code, which is barebones right now because I just...
1
3703
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
1
3173
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
6
3286
by: Hitesh | last post by:
import string import os f = open ("c:\\servername.txt", 'r') linelist = f.read() lineLog = string.split(linelist, '\n') lineLog = lineLog #print lineLog for l in lineLog:
3
1905
by: billiejoex | last post by:
os.listdir(path) return a list of file names independently if the path- argument used is absolute or relative: '/home/user' glob.glob, instead, return file names only if given path is relative: '/home/user/Desktop
4
3072
by: rajesh619 | last post by:
I'm new to programming. I have created a servlet which retrieves values from the database after a value is put into the HTML page to which it is attached. But during compilation, it shows two errors. Please help me in solving this error. import java.io.*; import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.net.*;
0
8053
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8380
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4007
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4066
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1638
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.