Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How do I find the particular field in a File?

( #159120=categorized question: print w/ replies, xml ) Need Help??
Contributed by velmani on Apr 15, 2002 at 09:43 UTC
Q&A  > files


Description:

Hi, I'm storing the informations of a student like his name and degree in a text file. How do i get the value of the field (column) like degree for a particular row in the file? Thanks in advance VELMANI

Answer: How do I find the particular field in a File?
contributed by particle

your perl script will need to know the structure of your data. how many fields? what are their names? what is the field seperator? what is the record seperator? once these things are defined, you can read in your data, and process it correctly.

see split for details of splitting fields. also, see perldata for explainations of scalars and arrays.

Answer: How do I find the particular field in a File?
contributed by ehdonhon

If you are experienced in using DBI, you could take a look at DBD::AnyData. As long as your data is being stored in an AnyData compatable format, you should be able to use a simple SQL command to retrieve your info:

my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'STUDENTS', 'CSV', 'students.csv' ); my $sth = $dbh->prepare("SELECT degree FROM STUDENTS WHERE STUDENT = + 'george'");
Answer: How do I find the particular field in a File?
contributed by Juerd

By reversing the method you used to store it.

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
  • Outside of code tags, you may need to use entities for some characters:
            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 surveying the Monastery: (5)
    As of 2014-07-26 13:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (177 votes), past polls