On my system, the block size is 4096 bytes. On an 8K file with 128 lines, we see:#!/usr/bin/perl if ($ARGV[0] eq 'line') { print "Line-at-a-time\n"; while (<STDIN>) { print if /perl/; } } else { print "All at once\n"; my @arr = (<STDIN>); foreach (@arr) { print if /perl/; } }
$ strace -e read /tmp/t29 line </tmp/t29.8192 >/dev/null ... read(0, "This is a line that contains the"..., 4096) = 4096 read(0, "This is a line that contains the"..., 4096) = 4096 read(0, "", 4096) = 0 $ strace -e read /tmp/t29 slurp </tmp/t29.8192 >/dev/null ... read(0, "This is a line that contains the"..., 4096) = 4096 read(0, "This is a line that contains the"..., 4096) = 4096 read(0, "", 4096) = 0Still, the diamond operator takes some time to operate, so slurping is still probably faster, but not because of I/O.
In reply to Re: Re: Re: Opening file and checking for data
by sgifford
in thread Opening file and checking for data
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |