P is for Practical | |
PerlMonks |
Re: Accepting either a filename or a handleby belden (Friar) |
on Jun 19, 2004 at 20:25 UTC ( [id://368202]=note: print w/replies, xml ) | Need Help?? |
Alternatively, if you don't like the ref solutions, you can use one of perl's Obscure Open Tricks
Then your_function() just relies on its caller to do the right thing. If you want to pass your_function() a filename to take as output, then you'd call it as you'd expect:
On the other hand, if you want to pass your_function() an already opened filehandle, and use that for output, then you'd call it as:
For more info on this, check out Obscure Open Tricks in perlopentut. There's a recommendation in there that you qualify the package name where OUTPUT is located, which I've ommitted in the code above. One thing worth noting is that the line
Must appear as written (i.e. with no spaces between the > and $out). Avoid these following variations, since they don't do the same thing as the line above
In Section
Seekers of Perl Wisdom
|
|