BEGINNER'S question re searching for text 
Author Message
 BEGINNER'S question re searching for text

     I would appreciate any answer to this extrememely elementary
question.  I've not been able to get this to run on our MacPERL, after
hours of experimentation.  
     I just want to 1.) open a file designated in a script eg "test1", 2.)
search that file for a regular expression eg "abc", and 3.) copy those
LINES that contain characters "abc" to the output screen or perhaps
another file, something like this.

#!/usr/bin/perl

if (open(MYFILE, "intest1")) {
     $_ = <MYFILE>;
     while (<>) {
          if (/abc/) {      
          print ($_);
          $_ = <MYFILE>;
          }
     }

Quote:
}

Many thanks,

Ralph Brands
Health Care and Epidemiology
University of British Columbia



Tue, 21 Oct 1997 03:00:00 GMT  
 BEGINNER'S question re searching for text

Quote:

>     I would appreciate any answer to this extrememely elementary
>question.  I've not been able to get this to run on our MacPERL, after
>hours of experimentation.  
>     I just want to 1.) open a file designated in a script eg "test1", 2.)
>search that file for a regular expression eg "abc", and 3.) copy those
>LINES that contain characters "abc" to the output screen or perhaps
>another file, something like this.

>#!/usr/bin/perl

>if (open(MYFILE, "intest1")) {
>     $_ = <MYFILE>;
>     while (<>) {
>          if (/abc/) {      
>          print ($_);
>          $_ = <MYFILE>;
>          }
>     }
>}

Ralph,

When you say "while (<>) " it is expecting input from stdin .. not MYFILE.

Try this instead:

#!/usr/bin/perl
if (open(MYFILE, "intest1")) {
     while ($_ = <MYFILE>) {
          print if (/abc/);
     }

Quote:
}

__END__

Mark Palmer
McHugh Freeman
Systems Administrator



Tue, 21 Oct 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Beginner's Perl question - trouble with a very simple search/pattern matching script

2. Beginner's question on clearing Entry/Text boxes

3. search text file, find substring, beginner help pls.

4. Beginner asks: Searching for keywords in a large database of memo's

5. perl's edge -- a beginner's question

6. Beginner with simple question on searching

7. substituting text in a var (beginner question)

8. Beginner Question about Text Box

9. Dumb*ss Perl Question

10. some beginner's questions

11. Beginner's question on string substitutions

12. Beginner's question about lists

 

 
Powered by phpBB® Forum Software