Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

How do I find the particular field in a File?

by velmani (Initiate)
on Apr 15, 2002 at 09:43 UTC ( [id://159120]=perlquestion: print w/replies, xml ) Need Help??

velmani has asked for the wisdom of the Perl Monks concerning the following question:

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
  • Comment on How do I find the particular field in a File?

Replies are listed 'Best First'.
Re: How do I find the particular field in a File?
by particle (Vicar) on Apr 15, 2002 at 12:29 UTC
    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.

      Is the information in the file stored in a pattern as in tab spaces etc? Also are you looking for a particular value or a value in a particular row. If it is a value you can use the matching like
      ~ m/word pattern/
      If you know the row then you can sort through the array
      $array[row]
      Shashidhar Iddamsetty
Re: How do I find the particular field in a File?
by ehdonhon (Curate) on Apr 15, 2002 at 13:30 UTC

    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'");
Re: How do I find the particular field in a File?
by Juerd (Abbot) on Apr 15, 2002 at 10:02 UTC
    By reversing the method you used to store it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://159120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-20 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found