*Assuming I understand the question any better or worse than anyone else*

May I ask why you are using a while(<FILE>) loop? It's going to set $_ to one line at a time, so setting an array to $_ isn't going to help you much...

You could try something like this:
my @filelines = <FILE>; #Read the entire file into an array my $whichline; #Declare a variable to hold the line number for(my $i = 0; $i = $#filelines; $i++){ #Go through the entire array +untill you find it or run out of lines if($filelines[$i] =~ m/TEXTTOMATCH/o){ #Attempt to match, use compi +le-once $whichline = $i; #If match, remember the line + and leave the loop. last; } }


Or if you want to find more than one line with that pattern:
my @filelines = <FILE>; #Read the entire file into an array my @whichline; #Declare a variable to hold the line number for(my $i = 0; $i = $#filelines; $i++){ #Go through the entire array +untill you find it or run out of lines if($filelines[$i] =~ m/TEXTTOMATCH/o){ #Attempt to match, use compi +le-once push(@whichline,$i); #If match, add to the list of current match +es } } #Now you know what lines had TEXTTOMATCH in them
Once you have the line with that, you can use splice() to remove the line if you wish, or do something else to it...

**Edit: Inserted comments in code and added multiple match**



"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS


In reply to Re: newbie question by Flame
in thread newbie questions on array access and control loops 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.