On Wed, Jun 13, 2001 at 04:30:01PM -0700, David Kenneally wrote:
> Hello-
> 
> This is a really basic question, sorry. Can anybody tell me why I get the
> following error when I run this script:
> 
> "Use of uninitialized value in numeric lt (<) at ./x2 line 8"

"Use of uninitialized value" means you're relying on an undef value to give
you something meaningful, and Perl thinks this is probably not what you
meant.

 
> #!/usr/bin/perl -w
> 
> 
> opendir DIRH, "/home/dwk/test" or die "can't open it: $!\n";
> @allfiles = readdir DIRH;
> closedir DIRH;
> foreach $temp (@allfiles) {
>   if (-M $temp < "0.5") {

This is line 8, of course, and your undefined value is obviously not "0.5",
so it must be the -M $temp.  -M will return an undefined value if the
underlying stat on the file failed.  This is can be caused by various
things, but the most likely reason is that the file $temp doesn't exist. 
Your problem probably lies in the fact that $temp is going to be a relative
filename (as all files returned by readdir are) that doesn't exist in your
current working directory.

What you need to do chdir, then opendir ".":

    chdir("/home/dwk/test") || die("chdir failed: $!\n");
    opendir DIRH, "." or die "can't open it: $!\n";
    ...

OR prepend the directory name to all of your files

    opendir ...
    @allfiles = map { "/home/dwk/test/$_" } readdir(DIR);
    ...


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to