473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

read multi lines of a file in perl

Hi all,
I have to read severals line of a document in perl. I wrote a program but with that am able to read only lines by line. eg if i have a file in which contents are:
Expand|Select|Wrap|Line Numbers
  1. process jkdgf
  2. jdk
  3. jhfk
  4. end process
  5. process jhdk
  6. jfka
  7. end process
  8.  
I have to read data betwenn process and end process. But am not able to.
my code is
Expand|Select|Wrap|Line Numbers
  1. while(<WORDLIST>)
  2. {
  3.     if (/process/)    #check for process
  4.     {
  5.             print "$_";
  6.  
  7.         if (/end process/)
  8.     {
  9.     last;
  10.     }
  11. }}
  12. close (WORDLIST);
  13.  
am just able to read only
Expand|Select|Wrap|Line Numbers
  1. process jkdgf
  2. end process
  3.  
as output....
i want output to be as
Expand|Select|Wrap|Line Numbers
  1. jdk
  2. jhfk
  3. jfka
  4.  
Many Thanks in advance..
Nov 5 '08 #1
3 2943
numberwhun
3,509 Expert Mod 2GB
Well, that is because you are looking for the terms "process" and "end process" and printing them when found. You are not telling it to do anything else. This script is essentially doing exactly what you have told it to do.

Try using something like this inside of the while loop:

Expand|Select|Wrap|Line Numbers
  1. unless ( $_ ~= /(?:process|end process)/) {
  2.      print $_;
  3. }
  4.  
Mind you, that is completely untested.

Regards,

Jeff
Nov 5 '08 #2
KevinADC
4,059 Expert 2GB
Well, that is because you are looking for the terms "process" and "end process" and printing them when found. You are not telling it to do anything else. This script is essentially doing exactly what you have told it to do.

Try using something like this inside of the while loop:

Expand|Select|Wrap|Line Numbers
  1. unless ( $_ ~= /(?:process|end process)/) {
  2.      print $_;
  3. }
  4.  
Mind you, that is completely untested.

Regards,

Jeff
New operator '~='? I think that is the mysterious and undocumented "maybe equals" operator. ;)

The answer to this question is found in the Perl FAQs. The second and or third FAQ on this page should help:

http://perldoc.perl.org/perlfaq6.html


.
Nov 5 '08 #3
numberwhun
3,509 Expert Mod 2GB
New operator '~='? I think that is the mysterious and undocumented "maybe equals" operator. ;)

The answer to this question is found in the Perl FAQs. The second and or third FAQ on this page should help:

http://perldoc.perl.org/perlfaq6.html


.
LOL!! Ok, so I had it backwards, it should be =~. Sorry for the confusion.

**I must revisit the FAQs one of these days**
Nov 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Konan | last post by:
Pardon the simple question, but I have just begun to learn PHP. So far so good - all the examples in my books actually work. One thing that none of them address is how to read a file of strings...
3
by: NNTP | last post by:
I'd lile to read the following file and output everything from 'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of "----------------------------------------" can perl do that?...
0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql socket file was arranged in a place other than...
2
by: Jan | last post by:
In a 2-page order form, not all applicants will complete it due to field validations. If I want to see data from incomplete orders, can this be done using some sort of session control so that each...
5
by: Radium | last post by:
Hi, what i want is something similar to th simple-xml extension of php, but for html. I have to analyze and read in certain tags from a html file in a comfortable manner. Is there a php...
8
by: Natti | last post by:
Hello, I have a perl program which parses an input file for specific error patterns and generates an output file with all these lines. One of the error patterns that I am looking at spans across...
1
by: ashok0866 | last post by:
I had created a macro to read data from an excel sheet and write the values to a text file. I had used "ActiveSheet.Range("GB" & k).Value" command to read the values from the excel. The issue...
6
by: bmerlover | last post by:
I'm trying to read each line, character by character, to determine if a line has a semicolon in it. I'm trying to count the number of lines that have a semicolon. In all of the files in one...
21
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.