Professional Web Applications Themes

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. #1

    Default 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. #2

    Default 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]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Paul Kraus Guest

Similar Threads

  1. how to check array element's values if this element isempty
    By jiecoldfusion in forum Macromedia ColdFusion
    Replies: 2
    Last Post: February 25th, 10:00 PM
  2. Is there a function to see if something is an element of an array?
    By Wiggins D'Anconia in forum PERL Beginners
    Replies: 0
    Last Post: September 30th, 05:05 PM
  3. [PHP] Array element from function return
    By John W. Holmes in forum PHP Development
    Replies: 1
    Last Post: August 24th, 03:41 PM
  4. Array element from function return
    By Wouter Van Vliet in forum PHP Development
    Replies: 0
    Last Post: August 24th, 03:24 PM
  5. Delete array element from inside function
    By JS Bangs in forum PERL Miscellaneous
    Replies: 6
    Last Post: July 2nd, 05:50 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139