If I now read this file into an array and then try to grep the array index, it just doesn't work.
Of course it works, it just doesn't do what you think it should do. Since we don't know what code you've got, what you want it to do, or what it currently does, you're probably not going to get very helpful replies until you provide that information.

See also How do I post a question effectively?.

Update: please mark your updates (like I did this one) and use <code> .. </code> tags to mark your code. it makes it a lot easier to read (and type). See also writeup formatting tips.

Anyway, I'm assuming you've omitted a few pieces in that code snippet that are actually there in the real code (like the part where you write to "clean_text").

Note that

my(@lines) = <MYINPUTFILE>; # read file into list
Puts the complete lines in @lines. That includes the newline character "\n". Since every line (except possibly the last one) ends with "\n" and $search does not, your match is not going to work. (See also chomp)

I also note that it's very likely the lines have other whitespace in them. It's probably easier to match using a regular expression:

# match the string "foo" on "word boundaries" my @line_numers = grep { $lines[$_] =~ /\bfoo\b/ } 0 .. $#lines;
or
# match lines containing the single word "foo", # ignoring whitespace my @line_numers = grep { $lines[$_] =~ /^\s*foo\s*$/ } 0 .. $#lines;
updated: bug fixed for the grep() expression.


In reply to Re: html into an array by Joost
in thread html into an array by monkeybus

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.