develooper Front page | perl.beginners | Postings from March 2002

RE: Search for a word in between words

Thread Previous | Thread Next
From:
Timothy Johnson
Date:
March 27, 2002 10:53
Subject:
RE: Search for a word in between words
Message ID:
C0FD5BECE2F0C84EAA97D7300A500D50025811C0@SMILEY

If you know that the word you're looking for is going to be the next line
after 'installation', you can try this:

open(INFILE,"file.txt");
while(<INFILE>){
   chomp($_);
   if($_ eq "Installation"){
      $word = <INFILE>; #assign the next line to the $word variable
	chomp $word;
	print $word;
      <INFILE>; #read past one more line to skip the next "installation"
   }
}

-----Original Message-----
From: Agustin Rivera [mailto:lists@eleqtriq.ws]
Sent: Wednesday, March 27, 2002 9:25 AM
To: Allison Ogle; beginners@perl.org
Subject: Re: Search for a word in between words


while(<IN>)
{
    $firstword=$middleword;
    $middleword=$lastword;
    $lastword=$_;
    if ($firstword eq "Installation" && $lastword eq "Installation")
    {
        print "FOUND $middleword\n";
    }

Would that work?

Regards,`
Agustin Rivera
Webmaster, Pollstar.com
http://www.pollstar.com



----- Original Message -----
From: "Allison Ogle" <aogle@ti.com>
To: <beginners@perl.org>
Sent: Wednesday, March 27, 2002 9:13 AM
Subject: Search for a word in between words


>
>
> To give you even more information, in my datafile, the word that I am
> searching for is 'marked' by the word in the line before it.  For example,
> the lines in my datafile look like..
>
> line 1
> line 2
> line 2
> Installation
> example
> Installation
> line 4
> line 5
> line 6
>
> and all I want is the word in between the words Installation.  Because I
> don't know what the word in between the words Installation will be, I'm
not
> actually searching for the word Installation but for the word in the next
> line after Installation.  Does that make sense?  Any ideas?
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About