Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 06:11 AM
Scott
Guest
 
Posts: n/a
Default 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.
  #2  
Old July 19th, 2005, 06:11 AM
bmay2068@hotmail.com
Guest
 
Posts: n/a
Default 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!
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles