in reply to Call sub first or later

I think that if the only time you call fraction() is if you have performed the test, then putting the test in the fraction() sub is just fine.

Now, personally, I would do the following:

$str = convert_to_fraction_if_needed( $str ); sub convert_to_fraction_if_needed { my $str = shift; return $str unless $str =~ /\d+_\d+/; return convert_to_fraction( $str ); } sub convert_to_fraction { my $str = shift; # Do stuff here return $converted_str; }

I like my functions to be atomic, but that's just me. Either way is maintainable.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Replies are listed 'Best First'.
Re: Re: Coding refactoring?
by kiat (Vicar) on Apr 26, 2004 at 15:38 UTC
    Thanks, dragonchild!

    It never occurred to me to break it down this way. Nice input :)