Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

name filehandle vs filehandle reference problem

by babel17 (Acolyte)
on Sep 23, 2011 at 18:53 UTC ( #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.

Comment on name filehandle vs filehandle reference problem
Select or Download Code
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
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? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-09-01 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (15 votes), past polls