in reply to All-purpose data dump subroutine

It can often be very useful to apply this sort of treatment to data being supplied on STDIN (in fact, I wouldn't call it "all-purpose" if it didn't support reading from STDIN).

This would mean skipping the "sysopen()" call (and doing "binmode STDIN" instead) when the "$fh" arg is, e.g. "-" or "stdin" or \*STDIN, or whatever you want to support in this regard. Also, if the given option hash wants a non-zero start offset, you'll have to just read through and do nothing for that many bytes, since you can't use seek() on STDIN. These are minor issues that are easy patch in, given how you've written the code.

The other thing is to have a "main()" function (a runnable script) that provides all the suitable command-line options (e.g. via Getopt::Long) that would allow the user to exercise the full potential of the dump_data subroutine (i.e. manipulate all the elements of %opts). Again, this is a pretty simple addition, given the code you've posted.

Altogether, thanks for posting this, and ++!

Replies are listed 'Best First'.
Re^2: All-purpose data dump subroutine
by liverpole (Monsignor) on Nov 28, 2006 at 16:39 UTC
    Some very nice comments!

    I've updated the code to work with STDIN as you suggested.  Supplying '-' in place of the filename will achieve this.

    Also, as you've suggested, I added switches to test each of the parameters (except for that of writing the data to a string instead of STDOUT).  Similarly, I've modified the syntax message to list each option.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/