473,387 Members | 1,641 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,387 software developers and data experts.

Parsing a text file into an array

I am new to perl, and have not found any good examples of parsing to
help me out. I have a text file that I am reading into an array that
has to be parsed out and put into another file. I have not found any
good examples of this. Does anyone know of any?

For example the text file looks like this...
900002 "Test,Test" 1/1/2004 F 21

with tabs inbetween each of the colums of the text file.
Jul 19 '05 #1
1 17511
sr*******@hotmail.com (Scott) wrote in message news:<26**************************@posting.google. com>...
I am new to perl, and have not found any good examples of parsing to
help me out.


Rather then asking outright you might want to try the code
yourself and then post problems you are having. Sample code
will help us help you. Also try some basic problem solving
using pseudo code...

i.e.

You know the format of the file so...

Open the file
While <more lines to read>
Read line
Tokenize the string based on tab
Store results into array
End While

Ask yourself the following questions;
1. How do I open a file for reading in PERL.
2. How do I read a line from the file using PERL.
3. You have the line, does PERL have a built in tokenizer (Parser!)

I'll give you some hints...

-open(FILEHANDLE, "filename");
-while(<FILEHANDLE>)
-chomp()
-split()

and one other function you should look up...
die()

There are lots of examples of the above functions on the newgroups.

Cheers!
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joey Martin | last post by:
I have been reading documentation on parsing. I need some help though. I have the following in a text file: $650 Number of Bedrooms 3 Air Conditioning? Yes Original Ad SOUTH, 3BR, air, basement....
5
by: SROSeaner | last post by:
I have a text file that is the result of using XMLHTTP object to pull back a page of search results from a search engine. So I have the entire results page in HTML, and want to break out each hit...
4
by: Carsten Kraft | last post by:
Hello Newsgroup, I think this is easy for you: I want to save the data line by line into an string array. eg. Text file: Array Line 1 Line1
6
by: kevin | last post by:
I need to parse an third party supplied delimited or fixed width text file into a datatable. The delimiter may vary. I am currently using a SteamReader to read each line and, for delimited...
2
by: DCDeshpande | last post by:
Hi, I am new to Java and need to parse a simple txt file into unique tokens and store them in a data structure. Can someone please recommend the most efficient way to do this? I found out that...
2
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm...
2
by: sevak316 | last post by:
Hello, I stored a text file into an array. Now I am going through the array looking for a particular string. When I find that string, I want certain things that come after it to be stored into a...
18
by: lka527 | last post by:
In the code, I have bold text where I have a question. I am not sure how to parse the file into different fields (right below with bold: machine,plan,study,scantype, date)... and I have more...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.