Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do I find the size of a file stored in another directory. I've tried : size "$file" = "$pre_file_size"; but I get errors, any idea what's wrong - or maybe a suggestion of another way of finding the file size. thanks

Replies are listed 'Best First'.
Re: size of a file
by jeroenes (Priest) on Jan 18, 2001 at 16:42 UTC
    Do you want to $size= -s $file?

    Jeroen
    "We are not alone"(FZ)

Re: size of a file
by Beatnik (Parson) on Jan 18, 2001 at 17:17 UTC
    You can use stat() as well, but that's less pretty :))

    (stat("filename"))[7]

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: size of a file
by PiEquals3 (Acolyte) on Jan 19, 2001 at 00:26 UTC
    A (possibly unneccesary) caveat:

    -s $file
    returns the number of BYTES in the file, which is what you want, right? If you want the number of records in the file, you'll need to either count delimiters or (if the records are fixed-length), divide the bytesize by the record length.
Re: size of a file
by Anonymous Monk on Jan 18, 2001 at 16:47 UTC
    I don't really understand how the size command works, so say if I'm in /tmp and I have a file called 'hello'. What I want to do is determine the size of the size 'hello' and store the size size as 'size_of_hello' eg: size -s "/tmp/hello" = "size_of_hello"
      As was just mentioned:
      $size_of_hello= -s "/tmp/hello";
      I have no idea where you have found a size command. Its not a perl builtin. On my Solaris workstation I have an executable called size, but it is used to print the sizes of sections in object files, probably not what you want.
      Do you mean something like this?
      $size= -s $file; die "Can't open file $!" unless open NEWFILE, ">/tmp/size_of_hello"; print NEWFILE $size,"\n"; close NEWFILE;