CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Accepting a string or a file handle or a reference?: Edit Log



BorisE
Novice

May 18, 2008, 12:08 PM


Views: 1288
Accepting a string or a file handle or a reference?

I'm moving some code into a module. In the process I'd like to make it a bit more versatile...

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)


Edit Log:
Post edited by BorisE (Novice) on May 18, 2008, 12:45 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives