Parsing a text file into an array

S

Scott

I having a bit of trouble trying to parse...

789798798 test,test 12/5/3005

with tabs between each column. Does any one have some suggestions?
 
P

Paul Lalli

I having a bit of trouble trying to parse...

789798798 test,test 12/5/3005

with tabs between each column. Does any one have some suggestions?

read the documentation for the 'split' function:

perldoc -f split

Then make an attempt. If you can't get it working, show what you have and
ask for assistance in fixing your code.


Paul Lalli.
 
T

Tad McClellan

Scott said:
I having a bit of trouble trying to parse... ^^^^^^
^^^^^^

Does any one have some suggestions?


Show what you have tried and we will help you fix it.
 
A

Anno Siegel

Scott said:
I having a bit of trouble trying to parse...

789798798 test,test 12/5/3005

with tabs between each column. Does any one have some suggestions?

What *is* a column? Ther are no tabs in the line above (probably lost
in news propagation). So are there three, four, or six columns?

Anno
 
J

Joe Smith

Scott said:
I having a bit of trouble trying to parse...

789798798 test,test 12/5/3005

with tabs between each column. Does any one have some suggestions?

If you go to http://search.cpan.org and enter TSV or Tab Separated Values
you'll get matches like

http://search.cpan.org/~jzucker/AnyData-0.10/AnyData/Format/Tab.pm
or
http://search.cpan.org/~ezdb/Data-Table-1.40/Table.pm
Data::Table - Data type related to database tables, spreadsheets,
CSV/TSV files, HTML table displays, etc.

For simple data, using perl's split() function will suffice.
-Joe
 
S

Sara

I having a bit of trouble trying to parse...

789798798 test,test 12/5/3005

with tabs between each column. Does any one have some suggestions?

Sho nuff scooter..

open F, $myFile;
my @lines = <F>;
close F;

for (@lines)
{my @line = split /\s+/; # assumes you have no whitespace in other fields
# if you DO, then split on tabs explicitly
# do what you want to do with this line
}

# take a break!


Cya,
G
 

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,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top