Parsing a text file into an array

S

Scott

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.
 
B

bmay2068

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top