CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:



May 8, 2001, 10:56 AM

Post #1 of 3 (493 views)
Filesize Can't Post

ok i am trying to show the filesize on something i am making i ripped this script off of fileman which shows the file sizes
sub fs {
# --------------------------------------------------------
# Prints out the file size.

my $size = shift;
my $formatted_size = int($size / 1024) . " kb";
$formatted_size == 0 ?
return "$size bytes" :
return $formatted_size;
and i made all the variables along with the filesize and crap but it still wouldn't show the file size of the file i needed. can anyone help me out with this please?


May 8, 2001, 12:46 PM

Post #2 of 3 (490 views)
Re: Filesize [In reply to] Can't Post

It seems that something is broken in the way you get the size of the file in the first place (atleast everything else seems like it would work). The -s modifier will return the size of a file, or you could use the stat(). Here is how I would do it though:

my $size = -s 'my_file.txt'; 
my $kb_s = int($size / 1024);

Of course, I would use sprintf to round because you can specify decimal places to round to, and it is more accurate.

Hope that helps!

r j o s e p h
"Violence is a last resort of the incompetent" - Foundation


May 8, 2001, 9:09 PM

Post #3 of 3 (483 views)
Re: Filesize [In reply to] Can't Post

Well thank you i am basically new at this stuff right now and i appreaciate it thank you.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives