Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

name filehandle vs filehandle reference problem

by babel17 (Acolyte)
on Sep 23, 2011 at 18:53 UTC ( [id://927600]=perlquestion: print w/replies, xml ) Need Help??

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):
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); };
I need to change this to:
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
    *packy::packy::packagename::fixed_string = $s; *fixed_string = $s; *$fh = $s;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found