Hi guys, I have a simple question, I wanna open a few sockets using single script, I have a code that opens 2 sockets:
use IO::Socket; my $sock1 = new IO::Socket::INET ( PeerAddr => '127.0.0.1', PeerPort => '80', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock1; my $sock2 = new IO::Socket::INET ( PeerAddr => '127.0.0.1', PeerPort => '80', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock2;
but i want to open more in cycle, however I cannot set correctly socket variable so it can vary in cycle, look:
for ($i=1;$i<10;$i++) { my ${sock$i} = new IO::Socket::INET ( PeerAddr => '127.0.0.1', PeerPort => '389', Proto => 'tcp', ); die "Could not create socket: $!\n" unless ${sock$i}; }

but I get error: Can't declare scalar dereference in "my" at f.pl line 12, near "} =" Execution of f.pl aborted due to compilation errors.

how should I set ${sock$i} in cycle so it be $sock1 $sock2....$sock10 ?? thanks

Original content restored above by GrandFather

thanks guys, you saved me much time :)

In reply to open many sockets in script by httpd

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.