Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unable to calculate file size greater than 1 GB using -s operator

Status
Not open for further replies.

himagauri

Programmer
Jun 29, 2006
10
US
My perl script is a very big script and performs a lot of complex tasks. One of the tasks within the script is to calulate the size of a file as follows:

$size = -s $filename;
$size = -1 unless defined($size);

When the file size is larger than 1GB for example 16376862124 bytes or 16 GB, the script returns $size = -1
For a file size less than 1 GB for example 775752944 bytes,
the correct file size is returned.

When I run another sample script performing just the above simple task of calculating file size, the correct size of 16376862124 bytes is returned for the larger file after a long time-about 40 minutes. The problem arises when the above task is within the larger script.

Can sombody suggest a solution to this problem?

I think perhaps it is a timing issue and in the larger script after a fixed time of 20 minutes or so, the perl interpreter moves to the next task/command in the script.

Is there someway I can increase the time limit to execute any command?
What is the default time limit set by the interpreter to execute any command?

Please suggest a solution to my problem.

-Thanks,
Regards,
Gauri
 
Which OS and Perl version are you using?

For me, on both Debian Linux i386 and ActivePerl on Windows 2000, it works fine for a file of around 3GB.
 
>> My perl script is a very big script and performs a lot of complex tasks.

Thats probably where the problem is. Sounds like your script is doing too much. Most likely you are running out of memory.

- Kevin, perl coder unexceptional!
 
>>Which OS and Perl version are you using?

OS is Suse Linux and Perl version is 5.8.3. But i have to work on a file that is 16 GB. or bigger.

>>Thats probably where the problem is. Sounds like your >>script is doing too much. Most likely you are running out >>of memory.

is there some other way of calculating size without utilising memory?
what about File::Stat? is it better or worse than '-s' file operator?
 
>> is there some other way of calculating size without utilising memory?

Not that I know of. Try using File::Stat but as far as I know it's just a way of more conveniently getting file statistics, not a more efficient way.





- Kevin, perl coder unexceptional!
 
Why not use `ls -l $filename` and get the size using regex?


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top