http://qs1969.pair.com?node_id=11127032


in reply to Is a here-doc a good way to retrieve data file contents for testing?

For testing purposes I would like my test function to return exactly what the file contains.

For tests, I think either of what you showed is ok, plus the variations shown by the others. Here are my comments on various ways to get multiline data, in particular data for tests:

Also note that if you need filehandles, you can use in-memory opens, which are relatively performant at splitting strings into lines.

open my $fh, '<', \<<'EOF' or die $!; Hello World EOF