Prints the size of a file in bytes. : File Output « File « Perl






Prints the size of a file in bytes.

    
#!/usr/local/bin/perl 

print ("Enter the name of the file:\n"); 
$filename = <STDIN>; 
chop ($filename); 
if (!(-e $filename)) { 
    print ("File $filename does not exist.\n"); 
} else { 
    $size = -s $filename; 
    print ("File $filename contains $size bytes.\n"); 
} 

   
    
    
    
  








Related examples in the same category

1.Print message in case of file open failure
2.Print out file line number
3.Print text to file
4.Numbering Lines in Multiple Files
5.Output file line by line
6.Output file