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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

V. large file::stat returns negative number! 2

Status
Not open for further replies.

Rovent

Technical User
Nov 16, 2001
61
0
0
US
Hullo all -

I'm trying to get the size of a very large file (60 GB), and every attempt i've tried to get the size returns a negative number (-195.000.000)

I've tried (stat($filename))[7], $size = (-s $filename), $size = $filename->size; they all return that same value.

All of those commands work with other files i'm trying to read (including one ~37 MB)

I've seen some threads that vaguely refer to recompling/reinstalling Perl, but this is the Perl that's integrated into HP Openview, so i'd rather not do that.

Can anyone suggest anything other than piping a LS/DIR command to a text file and parsing it? i've been beating my head against this so long i'm not even thinking straight. . .

thanks in advance!

- Alex
 
Try something like

open(SIZE, "ls -al $filname |);

while (<SIZE>) {
if (/$filename/) {
($j,$j,$j,$j, $size, $j, $j, $j, $j) = split(" ", $_);
print $size;
last
}
}
 
I am off subject but I just want to add a little comment about this line:
Code:
($j,$j,$j,$j, $size, $j, $j, $j, $j) = split(" ", $_);
You do not need this useless variable $j.

You could just use the 5th field like this:
Code:
($size) = (split(" ", $_))[4];
The parentheses around $size used to force interpretation of [tt]split[/tt] in list context.

But you could also explicitly not use the first values with:
Code:
(undef,undef,undef,undef, $size) = split(" ", $_);
The values after $size are not needed either: in fact [tt]split[/tt] will not even bother to split after the 5th field.
perldoc -f split said:
The LIMIT parameter can be used to split a line partially
($login, $passwd, $remainder) = split(/:/, $_, 3);

When assigning to a list, if LIMIT is omitted, or zero, Perl supplies a LIMIT one larger than the number of variables in the list, to avoid unnecessary work. For the list above LIMIT would have been 4 by default. In time critical application it behooves you not to split into more fields than you really need.

--------------------

Denis
 
rhymejerky -

ah, thank you SO much!

i managed to twist it a little and come up with this:

$size = (split(/\s+/,(`ls -la '$filename'`)))[4];

(the single quotes because the UNC name has a space in it. . .)

thanks again! you've saved my sanity on this one!

- alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top