This is the perfect moment for a Factory pattern. Write a function that returns IO::Socket::Inet objects, but you only pass the parameters along.
Your factory, is an engine of sorts. How it figures out what object you want is up to you. You can make configuration files, as someone suggested and your factoury would do, Factory->new( 'http://test.com' ) for port 80, or Factory->new('smtp://test.com').
Or you can write a Factory that takes all the parameters.
All in all, it'd reduce the code down to ...
$web = Factory->new( some parameters, a url, or numbers and hosts );
$smtp = ....
$something = ....
But otherwise, it's not THAT ugly in truth. YOu formated your code, it's easy to read. The factory thing is all i can really suggest.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.