stat() problem

P

Petterson Mikael

Hi,

I am trying to get change time of a directory with the following perl
snippet. @allfiles are containing the directory names.

foreach (@allfiles) {
if ( -d "$dir/$_"){
print "$dir/$_\n";
$mtime = (stat("$dir/$_"))[9]; # modify time
print "$mtime";
}
}

I get the following error message:

Use of uninitialized value in string at test.pl line 17

Which is this line:

print "$mtime";

Any hints!

//Mikael
 
A

Arndt Jonasson

Petterson Mikael said:
I am trying to get change time of a directory with the following perl
snippet. @allfiles are containing the directory names.

foreach (@allfiles) {
if ( -d "$dir/$_"){
print "$dir/$_\n";
$mtime = (stat("$dir/$_"))[9]; # modify time
print "$mtime";
}
}

I get the following error message:

Use of uninitialized value in string at test.pl line 17

Which is this line:

print "$mtime";

Any hints!

What does stat("$dir/$_") return? If an empty list, what does $! say?
 
M

Michele Dondi

Hi,

I am trying to get change time of a directory with the following perl
snippet. @allfiles are containing the directory names.

foreach (@allfiles) {
if ( -d "$dir/$_"){
print "$dir/$_\n";

as a side note, I'd do

#!/usr/bin/perl -l
# ^^
# ^^
# or set $\ local()ly later,
# according to how big your script really is.
# ...

use strict;
use warnings;

# You always include these lines, don't you?
# If you don't... do!

for (map "$dir/$_", @allfiles) {
next unless -d;
print;
print +(stat)[9];
}

# So that I can take advantage of $_ being the topicalizer...
I get the following error message:

Use of uninitialized value in string at test.pl line 17

Said this, you shouldn't get this error, so I guess it stems from
something else you didn't include in your post. Can you prepare a
full, self-contained, but still minimal example script exhibiting the
problem?


Michele
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top