-   Programming (
-   -   Perl: Why would I not be able to access file size with -s $myfile? (

SparceMatrix 01-05-2012 02:25 PM

Perl: Why would I not be able to access file size with -s $myfile?
I am trying to apply the -s operator to a directory of files. When I apply it to files in one directory, it works fine. But if I apply it to files in another directory, it doesn't work. I get an undefined variable if I use "my $size = -s $myfile" in this other directory, so that $size has no value.

What could be going wrong? Is it a permissions issue? I've tried changing that around. I've tried other tests and I see a change in write ability if I change owners, but nothing else. What else could it be?

What are the reasons the -s operator would not return a file size?

Cedrik 01-05-2012 03:27 PM

Is $myfile path correct ? Try check with -f $myfile

SparceMatrix 01-06-2012 11:39 AM

Is my face red ...
This is just embarrassing. I am constructing a file directory composed of bits of strings so that it's something like:


my $base_directory = "/here/is/my/directory;
my $folder = "MyFolder";
my $file_name = "SomeFile.file";
my $full_path = $base_directory . $folder . $file_name;

And I omitted the full path slashes between the base directory, folder and file name and got,


$full_path = "/here/is/my/directoryMyFolderSomeFile.file"
Instead of what I wanted which was


$full_path = /here/is/my/directory/MyFolder/SomeFile.file"
I was so wrapped up in applying this new file size operator, that I didn't check to see what I was actually getting in composing the full path.

Applying -f to see if I was actually getting a file exposed the whole mess right away.

Something like this fixed the problem:


$full_path = "$base_directory/$folder/$file_name";
Sorry to bother people with this one.

All times are GMT -5. The time now is 05:45 PM.