Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Parsing a text file into an array

Reply
Thread Tools

Parsing a text file into an array

 
 
Scott
Guest
Posts: n/a
 
      08-16-2004
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?
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-16-2004
On Mon, 16 Aug 2004, Scott wrote:

> 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.
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      08-16-2004
Scott <> wrote:

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


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      08-17-2004
Scott <> wrote in comp.lang.perl.misc:
> 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
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      08-29-2004
Scott wrote:

> 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/AnyD.../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
 
Reply With Quote
 
Sara
Guest
Posts: n/a
 
      08-30-2004
(Scott) wrote in message news:<. com>...
> 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
 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To write an array from the text file into an array variable using C amrutha0303 Software 0 08-03-2010 02:57 PM
parsing text file into array Hamanjam Perl Misc 3 04-03-2007 05:25 PM
converting a text file into an "insert into ..." file kublaikhan55@hotmail.com Ruby 5 07-23-2006 07:35 PM
Inputting text from a text file into a 2 -D array saltedcoffee C++ 2 04-05-2006 10:15 PM
Parsing a text file into an array Scott Perl 1 08-17-2004 04:21 PM



Advertisments