From: "Mauricio Fernández" Date: 2002-12-12T05:16:53+09:00 Subject: Re: Regular Expression Question On Thu, Dec 12, 2002 at 04:40:53AM +0900, Jonah wrote: > What would be the ruby equivalent of the following perl script? I > use the idiom often for quick templating tasks. It finds every > occurrence of %%WHATEVER%% in $source and replaces it with the results > of a subroutine call to sub whatever (lowercased) and is passed > $variable. > > $source=~ s/%%(.*?)%%/lc($1)->($variable)/eg ; > probably not very idiomatic, and EVIL source.gsub!(/%%([A-Z]*)%%/) { eval "#{$1.downcase} variable" } (take care of the binding in use) -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com * JHM wonders what Joey did to earn "I'd just like to say, for the record, that Joey rules." -- Seen on #Debian