Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting fields in a data file without a hash and without Schwartz

Status
Not open for further replies.

ysmith

Programmer
Feb 17, 2005
7
0
0
US
Hello,
I am having a similar problem as ljsmith91. I'm using perl to write to a data file and I want to be able to sort the lines based upon a sort parameter the user defines. The field names are first name, last name, email, school, and so on. For now, a hash is fine for our purposes because we don't have any duplicates, however, as more people use the service, the more likely it is that we're going to have more than one person with the same first name or last name, etc. Could anybody suggest an alternative to the hash, or describe a way in which we could adopt the hash to ignore duplicates? The Schwartzian (sorry if I butchered the spelling) Sort was already suggested, but wouldn't that require including all the data to be sorted within the file (which is a problem for us because the data is dynamically generated)? I'm still new at this, so correct me if I've misunderstood the Schwartz Sort concept or how to implement
Thanks
 
For something like this I think you may be better off storing the data in a database like MySQL and use perl to access it using SQL commands.
 
ysmith,

I think you are misunderstanding something, both of the sort methods I mentioned to you in the other thread will sort duplicate data just fine.
 
Perl is very flexible, how is your data stored now if it's dynamically generated? Likely only a simple transformation is needed to use one of the sorting methods mentioned in thread219-1011972

________________________________________
Andrew

I work for a gift card company!
 
KevinADC,
I think you're right--I am confused. In the Schwartz method, do I have to copy the whole data file at the end of the program, or does my data file just need to have the <DATA> designator at the top when I open it?

To answer your question icrf, the data is stored in the following manner within a simple data file:first_name, last_name, email_address (if published), school_attended, career_field, graduation_date, degree

Any suggestions on how I can store it differently/better/more efficiently?

Thanks
 
i do not grok "writing a data file"?
are there multiple files?

Each time you run YourProgram, is it creating the file from scratch?
or
is it incrementally adding lines?
and/or
is it only displaying the fields to the user in requested order - i.e., is the sorted order transitory or permanent?

depending on what is requred, and if the file is delimited by distinctive separators, i would try system()/backticks to *nix sort
 
It sounds like you need to start more basic. Doing complex multi-field sorting from a data file requires, at the very least, an understanding of how to work with files. Maybe give a look through perlopentut?

________________________________________
Andrew

I work for a gift card company!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top