473,587 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17519
sr*******@hotma il.com (Scott) wrote in message news:<26******* *************** ****@posting.go ogle.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(<FILEHAND LE>)
-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
3032
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. $650. Call 278-4171. First Appeared in the Newspaper Thursday, October 30, 2003 $775
5
1922
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 result from the text file as a unique item and do what I want with each hit result. Is there any suggested algorithms or any other techniques I...
4
9747
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
3788
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 files, String.Split() to break each line into an array based on the delimiter. The problem, as you may guess, is that the delimiter character is being...
2
2754
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 StringTokenizer class can be used for parsing the text. I need to know the most efficient dynamic data structure available in Java to store the words...
2
2581
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 looking for a single text stream that results from processing a file containing these directives. Even better would be an iterator(?) type
2
1670
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 variable until I reach a flag which tells me that I am done. I would like to repeat this for the entire file. So this is what I have so far: ...
18
8677
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 different files in the same format of this below. Others also have machine,plan, study, scan type, date as their information. right side of colon (:)...
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.