Length: 45 minutes
One of the more frequently-asked questions in the FAQ is:
How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
Unfortunately, the FAQ answer isn't very satisfying:
Those are operations of a text editor. Perl is not a text editor.
Now, however, there is a better answer. New in Perl 5.8, Perl is a text editor. The Tie::File module associates a Perl array with the lines of a file; you can modify the array with assignments, or push, or splice, or reverse, or whatever you prefer, and your changes will be instantly propagated to the file.
I'll introduce this module and show how to use it and how it works. I'll demonstrate some of its more advanced features. Next time you want to change one line in a file, delete a line from a file, insert a line in the middle of a file, or append to the beginning of a file, why not let Tie::File do the work for you?
Return to: Universe of Discourse main page | Perl Paraphernalia | Other Classes and Talks
mjd-perl-yak+@plover.com