Every once in a while I come across something that reminds me why I love Perl so much. This happened to me again this morning.
I had a file that needed to be split into a number of files. The start of each new file was indicated with a line that looked like:
==== file.ext ====where "file.ext" is the name of the new file.
The Perl code to split the file looks like this:
while (<>) { if (/==== (.*) ====/) { close STDOUT; open STDOUT, ">$1" or die "Can't open $1: $!\n"; } else { print; } }
Which is a lot simpler than I was expecting when I started to write it.