code_junkie

How do I get the size of a file in megabytes using Perl

Nov 14th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. my $size_in_mb = (-s $fh) / (1024 * 1024);
  2.  
  3. use Number::Bytes::Human qw(format_bytes);
  4. my $size = format_bytes(-s $file); # 4.5M
  5.  
  6. sub size_in_mb {
  7. my $size_in_bytes = shift;
  8. return $size_in_bytes / (1024 * 1024);
  9. }
  10.  
  11. my $size_in_mb = (-s $fh) / (1024 * 1024);
Add Comment
Please, Sign In to add comment