Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-05-2012, 02:25 PM   #1
Registered: Aug 2002
Distribution: SME Server, CentOS
Posts: 219

Rep: Reputation: 30
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?
Old 01-05-2012, 03:27 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
Is $myfile path correct ? Try check with -f $myfile
1 members found this post helpful.
Old 01-06-2012, 11:39 AM   #3
Registered: Aug 2002
Distribution: SME Server, CentOS
Posts: 219

Original Poster
Rep: Reputation: 30
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.

Last edited by SparceMatrix; 01-06-2012 at 11:42 AM. Reason: Added my fix.


file operators, file size, perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora 15: File size issues with FTP/Curl/Perl cheddarcheese Linux - Software 10 08-21-2011 01:10 PM
perl- check size to see if file is complete michael.barnes Programming 2 02-13-2008 06:20 PM
You don't have permission to access myFile.MP4 on this server. xpucto Linux - Newbie 4 09-24-2007 04:45 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
File access in Perl Paul_Lee Programming 7 08-25-2001 05:46 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration