Get the length of a file : stat « File « Perl






Get the length of a file

     


#!/usr/bin/perl

use strict;
use warnings;

print "Creating a file with the numbers 0-9.\n";
open FILE, "+>file.txt" or die "Unable to open file: $!\n";
print FILE "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
close FILE or die "Unable to open file: $!\n";

open FILE, "<file.txt" or die "Unable to open file: $!\n";
<FILE>;
my $length = tell( FILE );
print $length;
close FILE or die "Unable to open file: $!\n";

   
    
    
    
    
  








Related examples in the same category

1.Getting Information on a File
2.Get return value from stat function
3.Get the file size
4.File statistics returned from the stat command
5.File stats
6.Checks the permissions of a file
7.Call stat function from file handle
8.Lists files in directory; then gets info on files with stat
9.The stat Function for Windows NT File Attributes