Re: [QUIZ] Perl 'Easy' Quiz #2005-2

"Benjamin A. Okopnik" <[email protected]> Sat, 5 Feb 2005 14:05:09 -0500
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
I've had _bad_ problems with my email lately, so I missed the call for
it (thanks to Ben Thul, on whose email I'm piggybacking), but -


sub last_dot_only {
	return $_[0] unless $_[0] =~ /\./;
	( $a, $b ) = $_[0] =~ /(.*)(\..*)/;
	$a =~ y/.//d;
	"$a$b";
}


Another option, for those who prefer the "loop approach", might be


sub last_dot_only {
	for ( split //, reverse shift ){
		next if /\./ && $seen;
		$seen++ if /\./;
		$a .= $_;
	}
	scalar reverse $a;
}


Regards,
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *