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

Replies are listed 'Best First'.
Re^2: Is a here-doc a good way to retrieve data file contents for testing?
by Lotus1 (Vicar) on Jan 18, 2021 at 01:18 UTC
    Also note that if you need filehandles[...]

    I have wanted to do this before but didn't know about this feature. Thank you!