[oak perl] GNU and recursion
Belden Lyman
blyman at iii.com
Tue Feb 18 10:51:48 CST 2003
George Woolley wrote:
> My understanding from the GNU project site is that:
> GNU is a recursive acronym for "GNU's Not Unix'"
>
> So I'm thinking:
> GNU(0) equals GNU
> GNU(1) equals GNU's Not Unix
>
> My first question: what do
> GNU(2), GNU(3), etc. equal?
>
> And my second question:
> what would the Perl function look like
> for generating the values of GNU(0), GNU(1), GNU(2), etc.?
>
>
An iterative solution:
#!/usr/bin/perl
use strict;
use warnings;
print gnu_i('GNU',2),"\n";
sub gnu_i {
my ($str, $itr) = @_;
for ( 0..$itr ) {
$str =~ s/GNU/(GNU's Not Unix)/;
}
$str;
}
__END__
A recursive solution:
#!/usr/bin/perl
use strict;
use warnings;
print gnu_r('GNU',2), "\n";
sub gnu_r {
my ( $str, $itr ) = @_;
if ( $itr < 0 ) {
return $str;
}
$str =~ s/GNU/(GNU's Not Unix)/;
return gnu_r( $str, --$itr );
}
__END__
Belden
More information about the Oakland
mailing list