Find the answer to your Linux question:
Results 1 to 8 of 8
Is there anyway to compare elements of same array or any other way?? Please suggest?...
  1. #1
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114

    How can I compare elements of Same Array?

    Is there anyway to compare elements of same array or any other way??

    Please suggest?
    Switched to Scripting

  2. #2
    Just Joined!
    Join Date
    Oct 2007
    Posts
    9
    use strstr();
    strstr

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Sorry I did not get you.. is this a perl module...do I need to install it ?
    Switched to Scripting

  4. #4
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    please help us to understand your problem:

    suppose a, b and c are numbers, and {a,b,c} is an array.

    are you trying to compare a (first element) with b (second element)

    or what?
    the sun is new every day (heraclitus)

  5. #5
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Ok, what I am doing I am pushing the values in an array at runtime but before pushing the value I want to check whether it is already there in array or not. If it is already there then count is another variable which be will increased automatically and later I'll join the matched array element + count somehow.

    example @arr = ("192.168.1.0","192.168.2.0","192.168.3.0");

    want to check if
    $chk = "192.168.2.0";

    is already then it will become (element + count)
    $count =1;
    @ant = "192.168.2(2)";
    Switched to Scripting

  6. #6
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    i would suggest using a hash instead.

  7. #7
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Could you please suggest some example?
    Switched to Scripting

  8. #8
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    perldoc -q hash
    look for "How can I get the unique keys from two hashes?"
    you can see how the hash value is incremented. That should be your count.

Posting Permissions

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