May 18, 2008, 12:08 PM
Post #1 of 3
I'm moving some code into a module. In the process I'd like to make it a bit more versatile...
Accepting a string or a file handle or a reference?
Basically I'd like to be able to pass either data or a filehandle or reference to one of those and still have the sub work ok on it (if it is passed a filehandle it should slurp the file). I've seen modules elsewhere that claim to work like that...
I figure the first thing is to determine what was passed. I'm a bit confused as to how to do this though, since file handles seem to take so many forms e.g. typeglobs, objects, references?
I tried seeing how someone else's program did it and now I'm more confused, it has two entry points one for strings and the other for files. The files version makes a local typeglob and opens a file, then passes the typeglob to the string handling routine. How does that work? is there some behind-the-scenes magic at work here?
(This post was edited by BorisE on May 18, 2008, 12:45 PM)