Alex Goor wrote:
i have a data set of stock orders and i want to count the number of unique stock symbols in the set.
i have turned the data set into an array and based on the message spec, i can 
identify the stock symbols.  but i don't know how to make sure i'm only 
counting unique ones.

i had thought to do an if statement along the lines of

$symbolset = "@symbolset";
if $symbolset !~ /substr($message,17,6)/  #if the array doesn't contain the new 
symbol
{
#then add it to the array
push (@symbolset, "substr($message,17,6)

}

substr($message,17,6) is the symbol info within each line of the array of the 
data set.

the problem is that that doesn't work!

does anyone have any ideas how to do this?



[EMAIL PROTECTED] tmp]# cat !$
cat ./unique_stock.pl
#!/usr/bin/perl

use warnings;
use strict;

my @array = qw/yahoo google google msn msn msn yahoo/;

my %unique;

for (@array) {
   $unique{$_} = 1;
}

my $num_stocks = keys %unique;

print "Number of unique stocks are $num_stocks\n";
[EMAIL PROTECTED] tmp]# ./!$
././unique_stock.pl
Number of unique stocks are 3

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to