I see that someone has already answered, here is another example since you
are searching.
Since I am still new, writing it that way makes more sense, is more legible
to me :)

while ($line = <STDIN>) {
    #do something with that line, like a substitution
    $line =~ s/dog/cat/;
}

does that help? The while loop will read each line until it reaches EOF.


----- Original Message -----
From: "Rahul Garg" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, July 16, 2001 11:15 PM
Subject: Re: Parsing of a File and SEARCH ...........HELP!!!!!!!!!!!!!


>
>
> one more simple    Q...
>
> After opening the file ,
> How to read a file line by line.......................sample code
>
>
> Thax in advance.............
> waiting for replies.........................
>
>
>
>
>
>
>
>
>
>
>
> ----- Original Message -----
> From: Jeff 'japhy' Pinyan <[EMAIL PROTECTED]>
> To: Rahul Garg <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Monday, July 16, 2001 6:10 PM
> Subject: Re: Parsing of a File and SEARCH ...........HELP!!!!!!!!!!!!!
>
>
> > On Jul 16, Rahul Garg said:
> >
> > >1)I want to look out for a particular string in a file.
> > >   Actually there is only one strng in each line of a file.
> > >    How to search for it.............sample code........as i am new to
> syntax of perl
> >
> > For just finding ONE string in ANOTHER string, the index() function is
all
> > you need.
> >
> >   my $pos = index("jeffrey", "fre");   # 3
> >   my $pos = index("jeffrey", "jeff");  # 0
> >   my $pos = index("jeffrey", "free");  # -1
> >
> > As you can see, the function returns -1 on failure.  Please read the
docs
> > for the function:
> >
> >   perldoc -f index
> >
> > >2)I want to look out for a particular part(match) in a string in a
file.
> > >   Actually there is only one string in each line of a file.
> >
> > You need to open the file, and go through it, line by line, executing
the
> > index function on the line.
> >
> >   while (<FILE>) {
> >     if (index($_, $word) > -1) {
> >       # $word was found somewhere in $_
> >     }
> >   }
> >
> > Learn how to work with files:
> >
> >   perldoc perlopentut
> >   perldoc -f open
> >
> > --
> > Jeff "japhy" Pinyan      [EMAIL PROTECTED]
http://www.pobox.com/~japhy/
> > I am Marillion, the wielder of Ringril, known as Hesinaur, the
Winter-Sun.
> > Are you a Monk?  http://www.perlmonks.com/
http://forums.perlguru.com/
> > Perl Programmer at RiskMetrics Group, Inc.
http://www.riskmetrics.com/
> > Acacia Fraternity, Rensselaer Chapter.         Brother #734
> > **      Manning Publications, Co, is publishing my Perl Regex book
**
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to