Hi
I hope that you can help me. I have a problem that is probably simple but I am going the long way about solving it. Here is the problem:
I have an array of elements of the following format:
blah::status integer:22 blah::max integer:5 ...
I want the value after 'blah::' to be set as a variable to the number. e.g status=22; max=5.

I am doing this a very awkward way at the moment. Here is what I am doing:
I am defining the variables e.g my (status, max, ...)
Then I am using a for loop with if and elsif statements for every element in the array to assign the values
if ($array[$i] =~ /.*status.*/) { $status = $array1[$i]; $status =~ s/^.*://; } if ($array[$i] =~ /.*max.*/) { $max = $array1[$i]; $max =~ s/^.*://; } ...etc
This seems very long winded since the arrays can get very big and this method means that I need an if statement for every element. Can you suggest a better way?
Thanks in advance

In reply to Array problem by Anonymous Monk

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.