For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2007 > uninitialized value in a sort block









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author uninitialized value in a sort block
alexxx.magni@gmail.com

2007-06-29, 8:03 am

Hi Perlers,

I have a strange behavior happening sometimes to my filesystem
crawler:
inside tha wanted subroutine, I check the mod.times of the files:

@a=glob "$File::Find::name/*";
@a=sort {-M $a <=> -M $b} @a;

sometimes(rarely) what I get is:
Use of uninitialized value in numeric comparison (<=> ) at /usr/src/
chktimes line 33.

unfortunately I don't know why it's happening (file times seem ok to
me),
neither how to track the error, since the warning is printed on the
console, not synched with the print()'s I wrote here and there.

any hint?

thanks!

Alessandro Magni

Paul Lalli

2007-06-29, 8:03 am

On Jun 29, 6:38 am, "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com>
wrote:
> Hi Perlers,
>
> I have a strange behavior happening sometimes to my filesystem
> crawler:
> inside tha wanted subroutine, I check the mod.times of the files:
>
> @a=glob "$File::Find::name/*";
> @a=sort {-M $a <=> -M $b} @a;
>
> sometimes(rarely) what I get is:
> Use of uninitialized value in numeric comparison (<=> ) at
> /usr/src/ chktimes line 33.
>
> unfortunately I don't know why it's happening (file times seem
> ok to me),
> neither how to track the error, since the warning is printed on the
> console, not synched with the print()'s I wrote here and there.


I don't know why -M would be returning undef offhand (maybe you lack
permissions to one of the files?) But it shouldn't be that hard to
debug...

my @a=glob "$File::Find::name/*";
my @mtimes = map { [$_, -M $_] } @a;
for (@mtimes) {
print "File: '$_->[0]'. Mtime: $_->[1]\n";
}

See which files are giving you the problem, and then see if there's
anything "special" about that file on the disk.

Paul Lalli

anno4000@radom.zrz.tu-berlin.de

2007-06-29, 8:03 am

Paul Lalli <mritty@gmail.com> wrote in comp.lang.perl.misc:
> On Jun 29, 6:38 am, "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com>
> wrote:
>
> I don't know why -M would be returning undef offhand (maybe you lack
> permissions to one of the files?) ...


.... The file could have disappeared by the time -M is checked.

Anno
Mirco Wahab

2007-06-29, 8:03 am

alexxx.magni@gmail.com wrote:
> I check the mod.times of the files:
>
> @a=glob "$File::Find::name/*";
> @a=sort {-M $a <=> -M $b} @a;
>
> sometimes(rarely) what I get is:
> Use of uninitialized value in numeric comparison (<=> ) at /usr/src/
> chktimes line 33.
> any hint?



What would you expect to get from unix `stat` call (which is
what -M is based on), if you can't "stat" the file.

[http://perldoc.perl.org/functions/-X.html]
....
Unless otherwise documented, it returns 1
for true and '' for false, or the undefined
value if the file doesn't exist.
...

Regards

M.
alexxx.magni@gmail.com

2007-06-29, 8:03 am

thank you,
I feel really stupid, since it was <again> a special-character
problem. Usually I never encounter similar problems, since I seldom
use spaces or special chars in filenames.
But a crawler just goes, well, everywhere! So it ended up on a dir
whose name contained spec-chars.
Now it works well, with:

@a=glob quotemeta($File::Find::name) . "/*";

thanks a lot!

Alessandro

On 29 Giu, 13:05, Paul Lalli <mri...@gmail.com> wrote:
> On Jun 29, 6:38 am, "alexxx.ma...@gmail.com" <alexxx.ma...@gmail.com>
> wrote:
>
>
>
>
>
>
>
>
> I don't know why -M would be returning undef offhand (maybe you lack
> permissions to one of the files?) But it shouldn't be that hard to
> debug...
>
> my @a=glob "$File::Find::name/*";
> my @mtimes = map { [$_, -M $_] } @a;
> for (@mtimes) {
> print "File: '$_->[0]'. Mtime: $_->[1]\n";
>
> }
>
> See which files are giving you the problem, and then see if there's
> anything "special" about that file on the disk.
>
> Paul Lalli



Mumia W.

2007-06-29, 8:03 am

On 06/29/2007 05:38 AM, alexxx.magni@gmail.com wrote:
> Hi Perlers,
>
> I have a strange behavior happening sometimes to my filesystem
> crawler:
> inside tha wanted subroutine, I check the mod.times of the files:
>
> @a=glob "$File::Find::name/*";
> @a=sort {-M $a <=> -M $b} @a;
>
> sometimes(rarely) what I get is:
> Use of uninitialized value in numeric comparison (<=> ) at /usr/src/
> chktimes line 33.
>
> unfortunately I don't know why it's happening (file times seem ok to
> me),
> neither how to track the error, since the warning is printed on the
> console, not synched with the print()'s I wrote here and there.
>
> any hint?
>


Write debugging code that tests for undef:

for (@a) {
print "Modification time undefined for $_\n" unless (-M $_);
}

That should reveal the file that causes the warning.

> thanks!
>
> Alessandro Magni
>


You're welcome.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com