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.


In reply to name filehandle vs filehandle reference problem by babel17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.