...and the lack of testing shows.

syntax error at 766040.pl line 7, near "close"

You're missing a terminal semicolon at the end of line 6.

where file.txt is:

001: january 002: february 003: egypt 004: moon 005: saturday

The presence or absence of the line numbers reflects laziness and slow downloads but makes no difference here.

Suggestion: Use 3-arg opens and test each one (...|| die "Can't open $file: $!\n";.

Also, IMO, McDarren's response below strikes an appropriate chord. If the list of "wanted" words is in file.txt, then testing for their presence merely burns cycles and inconveniences electrons to no purpose whatsoever.

Hence, one might infer that OP failed to specify the issue adequately and that leads to another question: Is the intent to find the "wanted" words *anywhere* within the text or is it to test the text, line-by-line, and report per-line. One might guess from OP's wording that it's the former < update for clarity (in which case, slurping the file is fine [size issues aside] but would NOT be a good approach in the latter case ). but In /update> any case, leaving the reader guessing doesn't always get the best answer.

But, all that said, a question (perhaps ignorant) for akho: why scalar <$file>; for this application?


In reply to Re^2: How to club different lines of program into one by ww
in thread How to club different lines of program into one by ashok13123

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.