#!/usr/bin/perl use strict; use Benchmark qw( cmpthese ); use Data::Dumper; foreach my $file qw ( /dev/null /usr/share/dict/words /etc/passwd /opt/temp) { open my $IN1, '<', $file or die "could not open $file"; my @list = <$IN1>; seek( $IN1, 0, 0 ); my $dl = length( Dumper \@list ); print "$file\n"; cmpthese( -10, { while => sub { seek( $IN1, 0, 0 ); my @bob = (); while (<$IN1>) { push @bob, $_; } # my $x = Dumper \@bob; # die unless length($x) == $dl; # die @bob . ' ' . @list unless @bob == @list; }, list => sub { seek( $IN1, 0, 0 ); my @bob = <$IN1>; # my $x = Dumper \@bob; # die unless length($x) == $dl; # die @bob . ' ' . @list unless @bob == @list; }, array => sub { seek( $IN1, 0, 0 ); my $bob = [<$IN1>]; # my $x = Dumper $bob; # die unless length($x) == $dl; # die @$bob . ' ' . @list unless @$bob == @list; }, read => sub { seek( $IN1, 0, 0 ); read $IN1, my $bob, -s $IN1; my @bob = split( /^/m, $bob ); # my $x = Dumper \@bob; # die @bob . ' ' . @list unless @bob == @list; # die length($x), ' ', $dl unless length($x) == $dl; }, } ); }