Advertisement
tbrowder

read-file-test.pl

Feb 3rd, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # notes:
  4. # a run on juvat2 (2016-01-31) with 10 Gb input file was 2m10s
  5. # a run on bigtom (2016-01-31) with 10 Gb input file was 1m29s
  6. # the time for 'wc' on juvat2 was 1m57s
  7. # the time for 'wc' on bigtom was 1m30s
  8.  
  9. use v5.14; # 'say'
  10.  
  11. use autodie;
  12.  
  13. if (!@ARGV) {
  14. print <<"HERE";
  15. Usage: $0 <input file>
  16. HERE
  17.  
  18. exit;
  19. }
  20.  
  21. my $ifil = shift @ARGV;
  22.  
  23. die "FATAL: file '$ifil' not found.\n"
  24. if !-f $ifil;
  25.  
  26. my $fsiz = -s $ifil;
  27.  
  28. say " File '$ifil' size: $fsiz bytes";
  29.  
  30. open my $fp, '<', $ifil;
  31.  
  32. my $nlines = 0;
  33. my $nchars = 0;
  34. while (defined(my $line = <$fp>)) {
  35. chomp $line;
  36. ++$nlines;
  37. $nchars += length $line;
  38. }
  39.  
  40. # adjust for newlines being removed
  41. $nchars += $nlines;
  42.  
  43. say " Normal end.";
  44. say " For input file '$ifil':";
  45. say " Number lines: $nlines";
  46. say " Number chars: $nchars";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement