I see a few things which concern me, though the perl interpreter is generally more forgiving of questionable syntax than Monks are. As a stylistic point, your filehandles should at least start with a capital, if not be all caps. As for the warning you're getting, be sure that your pattern match is actually succeeding, otherwise $my_host and $my_url won't contain anything and so will be uninitialized. If the URL passed in is malformed, all sorts of badness will drop out. Also, are you aware that your varable declaration
my ($my_host, $my_request, $my_html_return) = ''; is only setting
$my_host? If you want to initialize all the variables to a zero-length string (which perl does automatically, however, if you ignore the warning), you'll need to specify a full list of empty strings (i.e.
('', '', '')). As for the match itself, take a look at
Ovid's
Death to Dot Star! about why your match isn't all it could and should be. Finally, be aware that your routine is duplicating the functionality of the
LWP module, which retrieves web pages quite reliably and has many more features than you would want to implement yourself. And it correctly handles real URLs :-).
Update
I actually ran your code, and ncw is correct: the warning is resulting from the lack of initialization for $my_html_return. You can either explicitly declare $my_html_return with the list of empty strings as above, or replace while(<my_socket>) {$my_html_return = $my_html_return . $_;} with while(<my_socket>) {$my_html_return .= $_;} as ncw suggests. But keep in mind you should generally initialize your variables just as a good coding practice.
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.