Hello your holinesses,
As my moniker implies, I am new to perl. I am trying to take input from STDIN that looks like this:
xs029
xs030
xs031
xs032
xs034

see if these hosts exist in a file and print the line in the file if they do. The contents of the file I'm searching through looks like this:

xs029 Host Node 129.202.178.129 - - - - - 10.200.178.129
xs030 Host Node 129.202.178.130 - - - - - 10.200.178.130
xs031 Host Node 129.202.178.131 - - - - - 10.200.178.131


and finally, here is my code. For some reason when I run it , it just sits there doing nothing. Any help would be much appreciated!
$infile="hosts.txt"; open(INPUT, $infile) || die "Error opening $infile\n"; my @allhosts = <INPUT>; foreach $approvhost (<STDIN>) { foreach $host (<@allhosts>) { if ($host =~ m/^$approvhost/) { print $host; } } }

In reply to matching a line from one file in another by New_to_this_stuff

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.