Tech77 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I have just started using Perl at work to help out with tasks here and there so I am new to this. Recently, I created this script to grab a list of records from a database. It actually works! I'm pretty thrilled.
open (FILE, "userstab.txt") || die "Cannot open file.\n"; open (NEWFILE, ">results.txt") || die "Cannot find or open file for ed +iting.\n"; while (<FILE>) { @zapschool = split (/\t/); if (m/zaps/i) { print NEWFILE "$zapschool[4]\n"; } } close FILE; close NEWFILE;
This gives me a list of all the entries in a column, but now I need to figure out how to use Perl to go through my new list, results.txt, and create a new list that holds the names and a count of how many times a partcular name appears on the list.
For example, my list contains college and university names. Many of them appear multiple times. I'd like to create a list where each unique record appears only once but with a frequency count of how many times it appears.
Can you offer some guidance on how to proceede? I'm not necessarily looking for finshed code, but more a point in the right direction so I can do it myself. Thank you.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Count and List Items in a List
by japhy (Canon) on Nov 01, 2005 at 15:01 UTC | |
Re: Count and List Items in a List
by Perl Mouse (Chaplain) on Nov 01, 2005 at 15:24 UTC | |
Re: Count and List Items in a List
by ikegami (Patriarch) on Nov 01, 2005 at 16:09 UTC | |
by Tech77 (Novice) on Nov 02, 2005 at 19:32 UTC | |
Re: Count and List Items in a List
by holli (Abbot) on Nov 01, 2005 at 16:13 UTC | |
Re: Count and List Items in a List
by perlfan (Vicar) on Nov 01, 2005 at 15:36 UTC | |
by ikegami (Patriarch) on Nov 01, 2005 at 16:16 UTC | |
by Tanktalus (Canon) on Nov 01, 2005 at 17:51 UTC | |
Re: Count and List Items in a List
by Tech77 (Novice) on Nov 02, 2005 at 19:15 UTC |
Back to
Seekers of Perl Wisdom