[Seattle-SAGE] Re: Need perl help - regex issue

Jeremy Mates jmates at sial.org
Mon Oct 24 13:55:47 PDT 2005


I recommend test driven development where possible: create as many test
cases as possible, and work until the code meets all the conditions.
Also handy is having a utility that re-runs the test periodically, or
after you change the file(s) being developed, so you code in one window,
and watch things break in another.

#!/usr/bin/perl -w
use strict;

use Test::More 'no_plan';

cmp_ok( trim_after_whitespace('asdf'),     'eq', 'asdf' );
cmp_ok( trim_after_whitespace('asdf    '), 'eq', 'asdf' );
cmp_ok( trim_after_whitespace(),           'eq', undef );
cmp_ok( trim_after_whitespace(''),         'eq', undef );

sub trim_after_whitespace {
  my $str = shift || '';
  $str =~ s/ \s .* $//x;
  return $str;
}



More information about the Members mailing list