Hi all,

I am after some advice on the best way to search an array for multiple values sequentially.

My scenario is this:

I have an array with anywhere up to 10 elements. The elements are Wifi Security types such as WPA, WPA2, WEP 64, WEP 128, etc.

What I would like to do is go through the array and select the best available security type according to what is available in the array. The array will differ as I work through different routers, so one router may only support up to WEP 128 while another will have WPA2 available. In my mind, I can see it working in that it will first search the array for WPA2, if it doesnt find it, it will then look for WPA, if thats not found, it will move on to WEP 128, and so on.

I am struggling to think of the best way to handle this. I have a vague idea but I think it will end up being a loooong bit of code with many many if statements and foreach loops.

Any advice would be greatly appreciated and I will happily provide more info if what I have said is not very clear.

Thanks.


In reply to Search an array for values sequentially by Doozer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.