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

Hi - I am trying to create a data manipulation script in which the data will be stored in a text file. A user will input the data on a form, it will be stored and then users will search the text file based on certain fields to view what they are looking for. On the input side, a lot of the info for each of the records will be the same (address for a certain organization). Is there anyway to indicate the organization and then the address will automatically be added to that record. Thanks - Alice

Replies are listed 'Best First'.
Re: need help with data manipulation
by shemp (Deacon) on Mar 28, 2005 at 19:31 UTC
    It really sounds like you should be using a database, having a lot of users Related to an organization is a clear sign of this.

    Is there anyway to indicate the organization and then the address will automatically be added to that record.

    Without any specification of the format of these text files, that question cant really be answered in a meaningful way. Are they going to be delimited files, or XML, or some other format?

    We'll need more info to help you

      And if the amount of data isn't too huge and the data isn't too hopelessly intertwined, you could use YAML instead of a database.
Re: need help with data manipulation
by jZed (Prior) on Mar 28, 2005 at 20:05 UTC
    I second the recommendation for a database. DBD::SQLite is easy to install, so are DBD::CSV and DBD::AnyData the later two would allow you to store the information in human-readable text files if that's a requirement. None of the three requires installation or maintenance of a separate database server. The basic design you need is one table that lists company names and addresses and a second table that has the company name as a field. Then, rather than storing the company names twice, you simply join the two tables when you want to access the information. If databases and SQL are a mystery to you, you could use AnyData which provides a tied hash interface to files in many formats.

    For, example if you have two files like this:

    [company.csv] company,address foo,NY bar,CA [employee.csv] name,company Joe,foo Sue,bar
    This script will print out each person with their company name and address:
    #!perl -w use strict; use AnyData; my $company = adTie('CSV','company.csv'); my $employee = adTie('CSV','employee.csv'); while (my $person = each %$employee) { printf "%s : %s :%s\n" , $person->{name} , $person->{company} , $company->{$person->{company}}->{address} ; }
Re: need help with data manipulation
by scmason (Monk) on Mar 28, 2005 at 19:41 UTC
    It seems like you would want to search through your previously entered data to find if the information had been entered previously. For instance: if the user enters "SomeCorp" as the organization, you search through the 'organizations' column in your data until you found 'SomeCorp', then you load that address as your current address.

    Internally, the data might be best storeed as a hash. Each item in your hash array would have associated keys like 'organization', 'address','phone','notes' etc. Searching through them with a forech loop is very simple.

Re: need help with data manipulation
by johndageek (Hermit) on Mar 28, 2005 at 19:59 UTC
    What have you tried s far?
    perhaps a sittle sample data as well would help.

    Enjoy!
    Dageek