The issue is that a prototype only gets associated with the subroutine after it has finished compiling; so by the time the compiler encounters the check_ip() inside the sub, it knows that check_ip() has a prototype, but it doesn't know which one yet.

As suggested by other posters, either drop the prototype (which doesn't buy you anything in the way you're using it), or declare the sub before defining it.

Note however that you still may get a warning - if your eval keeps failing, you'll hit a trigger that warns you for possible infinite recursion. Your sub is easily coded without recursion:

sub check_ip { { my $ip = eval { # Indirect object calls are so last millenium Net::IP->new(`curl whatismyisp.org`)->ip; }; return $ip if defined $ip; sleep 300; redo; } }
Of course, one can easily make a loop using while (or until), or even a goto as well.

In reply to Re: Is recursion consistent with "use warnings" by JavaFan
in thread Is recursion consistent with "use warnings" by jonathansamuel

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.