Re: Algorithm help for unique string searching/counting within an array.
- From: Thomas Koenig <Thomas.Koenig@xxxxxxxxx>
- Date: Tue, 30 May 2006 21:29:32 +0200 (CEST)
Paul Van Delst <Paul.vanDelst@xxxxxxxx> wrote:
I want to be able to search an array of strings (with many repeated elements) so I can
count the unique elements.
Are you sure you want to use Fortran for this? Languages like Perl or
awk have built-in arrays with strings as subscripts. Perl calls
them "hashes".
Here's a short Perl program (for illustration), which assumes that
all the strings are in separate lines.
#! /usr/bin/perl
while(<>) { # Loop over all entries in the array, putting values into $_ .
chomp; # Eat newlines
$string{$_}++; # Increment the hash element with the subscript $_ by
# one, creating the element if necessary.
}
print scalar(keys(%string)),"\n"; # Count the number of keys to the hash.
Maybe somebody has implemented hash tables in Fortran as a module
that you could reuse.
.
- Follow-Ups:
- Re: Algorithm help for unique string searching/counting within an array.
- From: Paul Van Delst
- Re: Algorithm help for unique string searching/counting within an array.
- References:
- Algorithm help for unique string searching/counting within an array.
- From: Paul Van Delst
- Algorithm help for unique string searching/counting within an array.
- Prev by Date: Re: Beginer needing help
- Next by Date: Re: Beginer needing help
- Previous by thread: Re: Algorithm help for unique string searching/counting within an array.
- Next by thread: Re: Algorithm help for unique string searching/counting within an array.
- Index(es):
Relevant Pages
|