Connecting Tech Pros Worldwide Help | Site Map

Parsing a text file into an array

  #1  
Old July 19th, 2005, 06:11 AM
Scott
Guest
 
Posts: n/a
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.
  #2  
Old July 19th, 2005, 06:11 AM
bmay2068@hotmail.com
Guest
 
Posts: n/a

re: Parsing a text file into an array


sroth1979@hotmail.com (Scott) wrote in message news:<26dbb845.0408160734.2a101f6f@posting.google. com>...[color=blue]
> I am new to perl, and have not found any good examples of parsing to
> help me out.[/color]

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!
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Reading a Text File Backwards C# stoogots2 answers 1 June 9th, 2008 08:56 AM
parsing text file into DataTable kevin answers 6 June 19th, 2006 07:35 PM
Parsing Data, Storing into an array, Infinite Backslashes supercomputer@gmail.com answers 6 July 21st, 2005 08:07 AM
Parsing data from a string into an array for each match William Holroyd answers 3 July 17th, 2005 06:08 AM