[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Stupid, non-Mac based PERL question



On Wed, 2 Jul 1997, Strider wrote:

> I think I've said everything in the subject.
> 
> I have a database laid out like this, in tab-delimited format:
> 
> Number[tab]Username[tab]Unneeded data[tab]ditto[tab]... there are fifteen
> fields total, and then a newline at the end.
> 
> I've looked through the instructions and PODs, and I just can't find this.
> The likely cause of that was being awakened early this morning to go to
> work. =p
> 
> All I want is the username, perferably in an array, one entry per username.
> How would I pattern match/replace to get this? Is that even the route I
> should take?
> 
> Thanks,
> - Seraph
> 

You can use pattern matching, but you don't have to.....you could do this 
something like:

open(FILE, "blah.txt") || die "Couldn't open file\n";
while (<FILE>) {
	@tmp = split(/\t/, $_);
	++$count{$tmp[1]};
}
close(FILE);

at this point, the hash %count will have all of the distinct usernames as 
keys, and the number of times that username occurred in the file as 
values.  Additionally, if you need the usernames in an array as you've 
described, you can do this:

foreach $username (keys %count) {
	unshift(@user, $username);
}

forgive me if there are any syntax errors....I didn't run this one 
through, just whipped it off the top of my head to give you some kind of 
idea.  Hope this helps.

Nam

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  Nam-June Joe                           namjj@eclipse.net
  US Applications Develpment             njoe@sbi.com
  Salomon Brothers, Inc.                 namjj@seas.upenn.edu
  University of Pennsylvania '96         http://www.eclipse.net/~namjj/

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Note: Any opinions expressed above are solely mine and do not represent
those of Salomon Brothers, Inc.


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch