uninitialized value in a sort block

A

alexxx.magni

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
 
P

Paul Lalli

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
 
A

anno4000

Paul Lalli said:
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
 
M

Mirco Wahab

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.
 
A

alexxx.magni

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

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
 
M

Mumia W.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,668
Latest member
SamiraShac

Latest Threads

Top