in reply to Re: Re: globbing,file handles and subroutines
in thread globbing,file handles and subroutines

You can simply pass the $sock to the subroutine and my it.. Its already a ref to a filehandle, hence you can work with it just like you are proposing... Here is a simple snippet to test sendmail on the local machine...
use strict; use IO::Socket; my $sock = IO::Socket::INET->new( PeerAddr => '127.0.0.1', PeerPort => '25', Proto => 'tcp', Type => SOCK_STREAM ); do_mail($sock); print $sock "quit\n"; close($sock); sub do_mail { my($handle) = shift; my $buf = <$handle>; print "Sendmail ", $buf ? "is OK\n" : "is not responding\n"; }
See? no alterations need to be made and the handles name is local to the sub routine.. the actual handle is still global I believe in this case, so I wouldnt suggest trying to have multiple sub routines reading the same handle at the same time..


/* And the Creator, against his better judgement, wrote man.c */

Replies are listed 'Best First'.
Re: Re: Re: Re: globbing,file handles and subroutines
by drake50 (Pilgrim) on Mar 15, 2003 at 04:57 UTC
    Yup. That works. I was offtrack thinking I had to do something really special...

    Thanks!