Checking file size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • banuruby
    New Member
    • Oct 2006
    • 1

    Checking file size

    hi,

    please help as how i can do the following using perl.

    there is a text file which contains the log details. once the textfile size crosses its maximum capacity, automatically it should create a next text file with the same name and starts using this new file.

    Thanks,
    banuruby
  • deep022in
    New Member
    • Sep 2006
    • 23

    #2
    Originally posted by banuruby
    hi,

    please help as how i can do the following using perl.

    there is a text file which contains the log details. once the textfile size crosses its maximum capacity, automatically it should create a next text file with the same name and starts using this new file.

    Thanks,
    banuruby
    ############### #####
    hi,

    use the stat function on the given file.
    for example
    @array = stat("file.txt" );

    this will return the various attributes of the file like read,write permission,file size in the @array

    the 8 th element of the array is filesize.

    then you can use the if-else loop to keep checking the file size and opening the next file for writting when the size exceeds the expected limit

    let me know whether above solution solved your problem

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      deep022in's solution will work, but a simpler bit of code would be to use the -s operator.

      my $size = -s "file.txt";

      The documentation is available here:
      perldoc -f "-s"

      Comment

      Working...