Posted by brian d foy on April 3, 2011
How would you get more than one line from a file? In the original Effective Perl blog that Joseph set up to support the first edition of Effective Perl Programming, he shows two possible techniques. One uses a foreach: my @lines; for (my $i = 0; $i < 10; $i++) { my $line = <STDIN>; [...]
Posted by brian d foy on November 13, 2010
Since Perl 5.8, you can treat a string as a file (Item 54. Open filehandles to and from strings). You can open a filehandle, read from the string, write to the string, and most of the other things that you can do with a file. There are some gotchas though, when you deal with that [...]
Posted by brian d foy on May 5, 2010
Addison-Wesley converted our chapter on “Files and Filehandles” to HTML and put it online for as a free sample chapter. I selected this chapter as the free sample because it was the most fun to write but also the most valuable to new Perl programmers. Filehandles are the way you interact with the world, and [...]
Posted by brian d foy on January 24, 2010
The conventional wisdom for slurping a file into a Perl program is to actually load the file into a program. We showed some of these in Item 53: Consider different ways of reading from a stream. There are several idioms for doing it, from doing it yourself: my $text = do { local( @ARGV, $/ [...]