Here's an answer, not necessarily the best, to PART 2, at least the string transformation portion thereof, but I'd strongly suggest you understand all of it before submitting it to your instructor lest embarrassing questions be asked. (See List::Util for the  sum() function)

>perl -wMstrict -le "use List::Util qw(sum); ;; my $s = 'r1y2g3g4y2r4r3y5y3g3g6g2r1'; my $r = 'r 1 y 2 g 7 y 2 r 7 y 8 g 11 r 1 '; ;; $s =~ s{ (([[:alpha:]]) \d+ (?: \2 \d+)*) } {$2 ${ \sum $1 =~ /\d+/g } }xmsg; print qq{'$s'}; ;; $s eq $r or die 'not what was wanted'; " 'r 1 y 2 g 7 y 2 r 7 y 8 g 11 r 1 '

Notice that I had to cheat a bit to make this work: the extra space at the end of the  $r "required output" string. Can you alter the substitution to get rid of this extra space, perhaps by adding a  (\z)? or  (\Z)? term to the regex and modifying the replacement expression accordingly?


In reply to Re: Splits and Arrays, PLEASE HELP:D by AnomalousMonk
in thread Splits and Arrays, PLEASE HELP:D by AwesomePerson

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.