Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

How do I find the particular field in a File?

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


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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2020-10-20 20:35 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (210 votes). Check out past polls.