Re: Searching in a line
- From: "John W. Krahn" <dummy@xxxxxxxxxxx>
- Date: Thu, 30 Aug 2007 21:00:36 GMT
lerameur wrote:
On Aug 30, 4:39 pm, "Jürgen Exner" <jurge...@xxxxxxxxxxx> wrote:lerameur wrote:I wrote this now: If it finds the work beth in the line, then isHere you are reading each line into $data
splits the line. otherwise print an error.
Now there is beth in the file ( i added it) but the program always
skips to the else statement, end prints it twice.
How should I modify the search if (/^beth/) ?
while ($data=<$fh>) {
if (/beth/) { #matches only if beth is in lineand here you are matching /beth/ against the default $_.
Is that what you meant to do?
jue
so you are saying this is no good:
$data=<$fh>
should I putting this into an array then ?
No, that is *not* what he is saying. You should either use $data in both places:
while ( my $data = <$fh> ) {
if ( $data =~ /beth/ ) { #matches only if beth is in line
Or use $_ in both places:
while ( <$fh> ) {
if ( /beth/ ) { #matches only if beth is in line
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Searching in a line
- From: lerameur
- Re: Searching in a line
- From: Jürgen Exner
- Re: Searching in a line
- From: lerameur
- Re: Searching in a line
- From: Peter Makholm
- Re: Searching in a line
- From: lerameur
- Re: Searching in a line
- From: Jürgen Exner
- Re: Searching in a line
- From: lerameur
- Re: Searching in a line
- From: lerameur
- Re: Searching in a line
- From: Uri Guttman
- Re: Searching in a line
- From: lerameur
- Re: Searching in a line
- From: Jürgen Exner
- Re: Searching in a line
- From: lerameur
- Searching in a line
- Prev by Date: Re: Searching in a line
- Next by Date: Re: Searching in a line
- Previous by thread: Re: Searching in a line
- Next by thread: Re: Searching in a line
- Index(es):
Relevant Pages
|
|