Which foreach loop is not iterating as many times as you want? Is it the last one (foreach $link(@links))? What are the command line options when you run it? What are the contents of linklist.txt? When I run this with no command-line arguments and linklist.txt containing the names of two web pages, I get two runs (although what I see is '1 Empty run' printed twice, which may or may not be what you want—see below). What should I see?

Note that you almost certainly don't want to roll your own option-parser. For example, your parser would be perfectly happy to accept two (or zero) arguments to -U or -x, which is probably not what you want. Something like getopt is probably more appropriate.

Note that the quotes around $link in the call check_link("$link") are unnecessary—they would 'stringify' $link, but it's just a simple scalar read from a file anyway.

What is the significance of $response and $part? You perform substitutions on them, but you never seem to use them.

That last foreach loop is probably more appropriate as a while loop anyway: Unless you need to know in advance all the lines you'll be processing (which doesn't seem to be the case), it's much more memory-efficient to process them one at a time.

UPDATE: I don't have Switch installed, so I used Perl 5.10's given instead. Since ikegami says below that switch is the problem, that could be why I'm not seeing anything.
UPDATE 2: If you do want to keep your hand-rolled parser, note that you must anchor your regexes at the beginning of the string. /-/ will match a string containing a hyphen anywhere, not just at the beginning.


In reply to Re: foreach problem by JadeNB
in thread foreach problem by Anonymous Monk

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.