Parsing a text file into an array

Discussion in 'Perl Misc' started by Scott, Aug 16, 2004.

  1. Scott

    Scott Guest

    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?
    Scott, Aug 16, 2004
    #1
    1. Advertising

  2. Scott

    Paul Lalli Guest

    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.
    Paul Lalli, Aug 16, 2004
    #2
    1. Advertising

  3. 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
    Tad McClellan, Aug 16, 2004
    #3
  4. Scott

    Anno Siegel Guest

    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
    Anno Siegel, Aug 17, 2004
    #4
  5. Scott

    Joe Smith Guest

    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/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
    Joe Smith, Aug 29, 2004
    #5
  6. Scott

    Sara Guest

    (Scott) wrote in message news:<>...
    > 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
    Sara, Aug 30, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott
    Replies:
    1
    Views:
    488
  2. saltedcoffee
    Replies:
    2
    Views:
    550
    Daniel T.
    Apr 5, 2006
  3. Replies:
    5
    Views:
    247
  4. Domenico Discepola

    Assistance parsing text file using Text::CSV_XS

    Domenico Discepola, Sep 1, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    444
    Domenico Discepola
    Sep 2, 2004
  5. Hamanjam

    parsing text file into array

    Hamanjam, Apr 3, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    82
    Mirco Wahab
    Apr 3, 2007
Loading...

Share This Page