IMHO, modules should do I/O when needed. In your current case, returning a hash ref with file content is doable due to the small size of the expected file contents. However, there are situations when modules have to process files as big as several GB, the module simply cannot return the file content (unless module returns it bit by bit, just adding a bit more hassle to calling program).
I also feel that the worry in OP is somewhat contradictory: if one assumes that the caller knows how and whether and where they need to open file and write file contents in a hashref out with correct permissions, then how can one not assume that they could know to send in correct filename/path with the right permissions for your module to write (after all, they do it in their calling program, right)?
In all, I see very little justification for providing hashref with file contents just so that users can deal with I/O themselves (unless there are special reasons unnamed in your question).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.