Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: $_[0] as a filehandle

by batkins (Chaplain)
on Oct 29, 2003 at 02:11 UTC ( #302884=note: print w/replies, xml ) Need Help??


in reply to $_[0] as a filehandle

There are a few reasons. First of all, you're using a reference to a glob as a filehandle - that's bound not to work. Also I'm not really sure what you're doing with split in myFonc; you might want to rethink that code. I would advise using lexically scoped filehandles. Something like this:
my $fh; open $fh, "<$myFile" or die "blah"; myFunc($fh); sub myFunc { my $fh = shift; while(<$fh>) { # do something } }
This works.

The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa

Replies are listed 'Best First'.
Re: Re: $_[0] as a filehandle
by sauoq (Abbot) on Oct 29, 2003 at 02:23 UTC
    First of all, you're using a reference to a glob as a filehandle - that's bound not to work.

    Uh... "Bound not to work"?

    perl -le '$x = \*STDOUT; print $x "Bzzzt."'

    That used to be the "accepted" way of passing handles around... :-)

    -sauoq
    "My two cents aren't worth a dime.";
    
      Yes, you're right. I should have tested it out before making that claim. :) I still prefer lexically-scoped filehandles whenever possible, but thanks for pointing out my mistake.

      The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa
Re: Re: $_[0] as a filehandle
by pg (Canon) on Oct 29, 2003 at 02:36 UTC

    On the contrary, it bounds to work. As sauoq pointed out in his 1st reply, the problem is on the receiving side, not the passing side.

    I tested, his Fonc actually worked, but not Func. You must have noticed that it passes the handler to them in exactly the same way, but Fonc and Func receive the parameter differently.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://302884]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2022-12-03 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?