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();
In reply to Re: Legacy Code
by repellent
in thread Legacy Code
by GotToBTru
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |