Here, I've written the first test.
use warnings; use strict; use Test::More; sub foo { my $linein = shift; my ($emailaddress, $hold1, $hold2, $hold3); my $nmbrvalues = 11; my $position1 = 0; my $position2 = 0; my $linelength = length($linein); for (my $cntr = 1; $cntr <= $nmbrvalues; $cntr++) { $position1 = $position2; $position1 = index($linein,'|',$position1); $position2 = index($linein,'|',$position1 + 1); my $fldlength = $position2 - ($position1+1); if ($cntr == 1) {$hold1 = substr($linein,$position1+1,$fldlength +);} if ($cntr == 7) {$hold2 = substr($linein,$position1+1,$fldlength +);} if ($cntr == 8) {$hold3 = substr($linein,$position1+1,$fldlength +);} if ($cntr == 9) { my $position3 = $position1+1; $position3 = index($linein,'@',$position3); if ($position3 > 0) { if ($position2 < 0) {$position2 = length($linein);} $fldlength = $position2 - ($position1+1); $emailaddress = substr($linein,$position1+1,$fldlength); } #end of IF if ($position3 <= 0) {$emailaddress = "mgrs\@server.com";} } #end of if } #end of FOR return ($emailaddress, $hold1, $hold2, $hold3); } is_deeply( [ foo("") ], [ "mgrs\@server.com", "", "", "" ] ); ### add more tests, edge cases, use cases, spec expectations, etc. done_testing();

Once you're done adding tests, you can modify foo() to your heart's content. The tests must still pass.

In reply to Re: Legacy Code by repellent
in thread Legacy Code by GotToBTru

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.