You mean something like:

use Data::Dumper; use Fatal qw(open close); open my $log, '>', $path_to_log; my_print_routine( $log, Dumper( \%some_var ) );

Update ... I imagine your subroutine just uses print, with no room for specifying a filehandle. Something like:

<code> sub my_print_routine { print for @_; print "\n"; }

You could select your filehandle to make it the default output, but that doesn't work if you also print to STDOUT. You could modify the print routine to check whether the first arg is a filehandle, and select it there, saving the previous value to select it back at the routine exit.

P.S. Bareword fielhandles and two-argument open are so Perl4 ... check out 'perldoc -f open' for the modern way.

Update 2 ... I dunno about others, I would check the first arg by seeing if : 'GLOB' eq ref $_[0]. if you had a valid reason for passing around GLOBs, that would fail.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: passing Dumper output to print subroutine? by TomDLux
in thread passing Dumper output to print subroutine? by bigtiny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.