Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How do I retrieve specific column values from a table of records?

( #16960=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Jun 08, 2000 at 01:05 UTC
Q&A  > regular expressions


Description:

The file is in the form of records and columns. I want to retrieve values only for a specific coloumn.How do I do that? EX:
name address phone city chang 12, annie road 201-243-6751 newark ming 13,dgadadgagd 62839871273 trenton gigi 14,gasdha 982318791 wilmingto
I want to retrive values for phone and address columns only.

Answer: How do I retrieve specific column values from a table of records?
contributed by le

It'd be easy if your file had a unique data seperator, like ";" or maybe "|". Then you could split() the rows on that seperator.

open (FILE, "data.txt") or die $!; while(<FILE>) { @array = split(/;/); print $array[1], $array[2]; } close(FILE);
Looks like the original data was tab-separated. split("\t") would work there. -- Ed.
Answer: How do I retrieve specific column values from a table of records?
contributed by BBQ

Please check out the Open Flat File node.
I hope that helps.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (17)
    As of 2015-07-31 15:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (278 votes), past polls