Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Legacy Code

by repellent (Priest)
on Apr 03, 2011 at 06:16 UTC ( [id://897154]=note: print w/replies, xml ) Need Help??


in reply to Legacy Code

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://897154]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found