"slurping" in a whole file into a scalar variable sounds like a good idea in this case. $text = <IN>; looks fine to me. There is no need for @text = <IN>.

I would suggest the use of the Perl function index() rather than regex in this situation.

index requires an exact match and so you should case search term and search text to be the same. But this "casing" operation is very fast. The index function will quit on the first match which is an advantage over regex this situation.

As always, your mileage may vary! Short "how to" is shown below.

#!/usr/bin/perl -w use strict; my @listOfWords = qw (january february egypt moon saturday zoos zoo thingies thing ); my $text = "moon. I love full moons but this it has been a long thing since yesterday on the beach. And a whole buch of BLAH.\nYet another february line.\n More jan stuff goes here. What a zoo this text searching thing can be!"; print"\n\nUsing ListOfWord Tokens\n"; foreach my $word (@listOfWords) { if ( index($text,"$word")>= 0) { print "word: $word\t found\n"; } else { print "word: $word\t NOT found\n"; } } __END__ Using ListOfWord Tokens word: january NOT found word: february found word: egypt NOT found word: moon found word: saturday NOT found word: zoos NOT found word: zoo found word: thingies NOT found word: thing found

In reply to Re: How to club different lines of program into one by Marshall
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.