Help for this page

Select Code to Download


  1. or download this
        open (FILE, "foo.txt");
        my @lines = <FILE>;
        close FILE;
    
  2. or download this
        open (FILE, "foo.txt");
        my @words = map { split } <FILE>;
        close FILE;
    
  3. or download this
        my @words = map { split(' ', $_) } <FILE>;
    
  4. or download this
    s/[.,!\?]\B//g
    
  5. or download this
        open (FILE, "foo.txt");
        my @words = map { s/[.,!\?]\B//g; split; } <FILE>;
        close FILE;
    
  6. or download this
        open (FILE, "foo.txt");
        my @lines = map { s/[.,!\?]\B//g } <FILE>;
        close FILE;
    
  7. or download this
        open (FILE, "foo.txt");
        my @lines = map { s/[.,!\?]\B//g; $_; } <FILE>;
        close FILE;
    
  8. or download this
        open (FILE, "foo.txt");
        my @lines = map { chomp; $_; } <FILE>;
        close FILE;
    
  9. or download this
        open (FILE, "foo.txt");
        my @lines = <FILE>;
        chomp(@lines);
        close FILE;
    
  10. or download this
    Benchmark: timing 100 iterations of chomp, map...
        chomp: 31 wallclock secs (29.17 usr +  0.54 sys = 29.71 CPU)
          map: 37 wallclock secs (34.63 usr +  0.59 sys = 35.22 CPU)