in reply to Multiline RegExp. A Better Way?

First off, the best code is code that works. As your code functions, everything else is necessarily subjective.

That said, I would modify your slurp function to look like:

sub slurp { my $file = shift; local $/; open my $fh, '<', $file or die "Can't open $file: $!"; return <$fh>; }

The big changes here are swapping to indirect filehandles and 3 argument open. Indirect filehandles are guaranteed not to collide with a previously existing file handle and will automatically close out once the variable goes out of scope. See Indirect Filehandles in perlopentut for more virtues. 3-argument open doesn't really matter in this case, but it protects you from some malicious vectors so it's usually considered a good habit to get into. I removed the = undef from your $/ localization, since that is redundant. I explicitly named the input parameter and explicitly returned to make intent more obvious to the casual reader.

Since you are outputting CSV, I would also likely use an explicit CSV module, such as Text::CSV. Again, it doesn't matter in this case, but it handles escaping which may matter to you in the future.

Finally, rather than using a while with a long multiline regex, I'd probably either do a streaming parser or a split. The longer the regex, the easier it is to break and the harder it is to fix. But, as far as they go, yours is pretty clean.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.