Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Use of unitialized variable?

by athomason (Curate)
on Aug 29, 2000 at 00:50 UTC ( [id://30042]=note: print w/replies, xml ) Need Help??


in reply to Use of unitialized variable?

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://30042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-16 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found