Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: simple ques...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 10996 of 12002
Post > Topic >>

Re: simple question

by krahnj@[EMAIL PROTECTED] (John W. Krahn) Apr 27, 2008 at 09:58 AM

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.

Use a hash.  Hash keys are always unique.

> i had thought to do an if statement along the lines of 
> 
> 
> $symbolset = "@[EMAIL PROTECTED]
";
> if $symbolset !~ /substr($message,17,6)/  #if the array doesn't contain
                     ^^^^^^^
You can't execute a function inside a string.

perldoc -q "How do I expand function calls in a string"


> the new symbol
> {
> #then add it to the array
> push (@[EMAIL PROTECTED]
 "substr($message,17,6)
> 
> }

my %symbolset;

# more code here

# increment count of unique data
$symbolset{ substr $message, 17, 6 }++;



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
 




 3 Posts in Topic:
simple question
a_goor@[EMAIL PROTECTED]   2008-04-27 09:36:15 
Re: simple question
krahnj@[EMAIL PROTECTED]   2008-04-27 09:58:03 
Re: simple question
rich.japh@[EMAIL PROTECTE  2008-04-27 12:47:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 10:16:43 CDT 2008.