This has me puzzled. I'm cleaning up a subroutine a co-worker wrote some time ago. When I turned on use strict and the -w flag, I get the warning:
Use of uninitialized value at ./gethtml.pl line 16, <my_socket> chunk +1.
This is the offending subroutine (spaced out a bit to make it more readable):
#/usr/bin/perl -w #gethtml.pl : HTML fetch and return. 28 MAR 2000 rev 1 use Socket; use strict; sub gethtml { my $my_url = $_[0]; my ($my_host, $my_request, $my_html_return) = ''; ($my_host, $my_url) = ($my_url =~ m#(.*?)/(.*)#); $my_request = "GET \/$my_url HTTP/1.0\nAccept: */*\nHost:$my_host\nUse +r-Agent: WebMangle/1.0\n\n"; socket(my_socket, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || retu +rn "Socket Error: $!"; connect(my_socket, sockaddr_in(80,inet_aton($my_host))) || return "Con +nect Error: $!"; send(my_socket, $my_request, 0x0); while(<my_socket>) {$my_html_return = $my_html_return . $_;} #above line is the offending one close my_socket || return "Close Error: $!"; return $my_html_return; } 1;
while admittedly trivial, I like my code warning free. Is it telling me that the my_socket filehandle isn't initialized ? how can I initialize this? (maybe I need more caffeine.. :P )

In reply to Use of unitialized variable? by Arsenal

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.