Re: Searching in a line



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 is
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>) {

Here you are reading each line into $data

if (/beth/) { #matches only if beth is in line

and 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 ?

k

.



Relevant Pages

  • Re: Searching in a line
    ... splits the line. ... Now there is beth in the file but the program always ... I am saying you should make up your mind if you want to use the default ...
    (comp.lang.perl.misc)
  • Re: Dynamic variables - from INI files ...
    ... Naturally, in your own code, you would read all of the data from the INI file and assign it to $data, perhaps like so: ... Read "perldoc perlre"; I should've split it into two statements for clarity: ... The line above splits $data, and it splits on spaces, newlines or equal signs. ... The resulting array is a bunch of NAME VALUE pairs, and that's perfect for assigning to a hash. ...
    (perl.beginners)
  • Re: Why so few 10ks?
    ... I am not saying that going out faster than the optimal even splits ... it is just that he's not fast enough to hold that pace. ... I don't say that a positive splits strategy necessarily produces slower times ...
    (rec.running)
  • Re: Need help with string splitter.
    ... > I'm working on a program which splits a long string into a series of ... The program prints out the string again by printing out each ... > occupied segment of the array, ... and it stops copying data into the array after the first ...
    (comp.lang.cpp)
  • Re: Searching in a line
    ... lerameur wrote: ... splits the line. ... Now there is beth in the file but the program always ... but a small machine shop where you ...
    (comp.lang.perl.misc)