Quantcast
Viewing all articles
Browse latest Browse all 183

Mundane Tasks — Perl to the Rescue

“What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?” Larry Wall in <1992Aug26.184221.29627@netlabs.com> I wanted to put all the quotations from my quotation file (a 5.1 MB text file with 74731 lines of text) into different text files. One file for each quotation. I already have an empty line separating each quotation in the quotation file, but copy-and-pasting the quotations into new files and saving them manually would take too long. After all, there are 19834 quotations (it’s a hobby). So, I decided to dust off my very, very basic knowledge of Perl. And with the help of sites like perlmaven.com hacked together a simple script that does the work for me. Take into account that the script is badly written, likely much more complex than it should be — but it worked well. Putting the quotation file and the script file in the same folder and executing it via Terminal on the Mac (OS X comes with Perl, yeah) and — presto! use strict; use warnings; # open the quotes source file my $filenameInput = 'all_quotes.txt'; open(my $fhi, '<:encoding(UTF-8)', $filenameInput) or die "Could not open file [...]

Viewing all articles
Browse latest Browse all 183

Trending Articles