Hi All,

I encountered a parse problem and I'm hoping one of your experts can help me with.

I have a text string which I want to parse into 2 separate variables. The string is made up of 2 portions, <portion1><portion2>, where portion1 can be any texts but portion2 is one of the following Crit, Maj, or Okay.

#Sample strings in an array: my @a = ('SystemMaj', 'MemoryCrit','ServerOkay', 'MemoryOkay');

How would you write the code to accomplish this? I tried the following but failed.

#code sample my @a = ('SystemMaj', 'MemoryCrit','ServerOkay', 'MemoryOkay'); foreach my $v (@a) { $v =~ m/(\w+[^(?:Crit|?:Maj|?:Okay])(\w+)/; print "1: $1 2:$2\n"; }
#sample output 1: System 2:Maj #correct 1: Memo 2:ryCrit #should be 1: Memory 2: Crit 1: Serve 2:rOkay #should be 1: Server 2: Okay 1: Memo 2:ryOkay #should be 1: Memory 2: Okay

Thanks for your help.

fujiman

In reply to Parse String Question by fujiman

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.