# Is there a function to see if something is an element of an array? - PERL Beginners

I have a long list of IP addresses I am going to be reading in (using regexps) and then seperating out into a list of IP addresses. I don't want the IP addresses to be printed if they are not unique. Is there a way to check if a string already has an element in a stack? i.e. push stack, \$_ if is_unique(\$_, stack); ? Or would I have to code that myself? -Dan...

1. ## Is there a function to see if something is an element of an array?

I have a long list of IP addresses I am going to be reading in (using
regexps) and then seperating out into a list of IP addresses. I don't
want the IP addresses to be printed if they are not unique.

Is there a way to check if a string already has an element in a stack?

i.e. push stack, \$_ if is_unique(\$_, stack); ?

Or would I have to code that myself?

-Dan

Dan Anderson Guest

2. ## RE: Is there a function to see if something is an element of an array?

You could use a hash instead.

Set the key to the ipvalue and the value to 1.

If (\$ips{\$thisip}) {
}

HTH
Paul

-----Original Message-----
From: Dan Anderson [mailto:danmathjunkies.com]
Sent: Tuesday, September 30, 2003 12:58 PM
To: [email]beginnersperl.org[/email]
Subject: Is there a function to see if something is an element of an
array?

I have a long list of IP addresses I am going to be reading in (using
regexps) and then seperating out into a list of IP addresses. I don't
want the IP addresses to be printed if they are not unique.

Is there a way to check if a string already has an element in a stack?

i.e. push stack, \$_ if is_unique(\$_, stack); ?

Or would I have to code that myself?

-Dan

--
To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]

Paul Kraus Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•