babel17 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to update some old perl code (that doesn't use strict refs or strict anything else *arrgh*) to add an additional case using IO::Socket::Socks. The problem is that the old code is using socket(), and forces the filehandle name. Many other parts of the code depend on this name.
Old Code (error handling removed for brevity):I need to change this to:use Socket; my $host = "teh-web-box"; my $port = "80"; my $phost = "teh-proxy-box"; my $pport = "1080"; my $fh = "fixed_string"; #part 1 socket($fh, PF_INET, SOCK_STREAM, getprotobyname("tcp")) my $paddr = pack_sockaddr_in($port, inet_aton($host)); eval { $SIG{'ALRM'} = sub { die; }; alarm( 5 ); connect( $fh, $paddr ); alarm(0); };
use Socket; use IO::Socket::Socks; my $host = "teh-web-box"; my $port = "80"; my $phost = "teh-proxy-box"; my $pport = "1080"; my $fh = "fixed_string"; my $s; if ( no_proxy() ) { #part 1 ... } else { $s = new IO::Socket::Socks( ProxyAddr => $phost, ProxyPort => $pport, ConnectAddr => $host, ConnectPort => $port, ); } # now reconcile $fh and $s.
I need a way to make $fh be a named handle for the socket that $s is a reference too. Is this possible? Is there some other way to do the same thing? If I had the luxury of time, I would simply rewrite all the code to use IO::Socket everywhere, but that's simply not an option here.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: name filehandle vs filehandle reference problem
by Anonymous Monk on Sep 24, 2011 at 00:01 UTC |