[Prev][Next][Index][Thread]
Re: Some inquiries about Dylan tutorials and documentation
In article <38D9118C.6CCBEC93@openscript.com>, James
<james@openscript.com> wrote:
> If this offer goes for anyone, I'd love to see the following Perl code
> translated.
>
> sub Template {
> local(*FILE); # filehandle
> local($file); # file path
> local($HTML); # HTML data
>
> $file = $_[0] || die "Template : No template file specified\n";
>
> open(FILE, "<$file") || die "Template : Couldn't open $file : $!\n";
> while (<FILE>) { $HTML .= $_; }
> close(FILE);
>
> $HTML =~ s/<!-- \\$(\\w+) -->/${$1}/g;
>
> return $HTML;
> }
>
> It basically looks through an html document for Perl variables and
> replaces them with their values as computed by perl. Pretty slick when
> creating dynamic web pages.
Can't be done -- Dylan deliberately doesn't have the capability commonly
known as "eval" (e.g. in Lisp and in Perl as well), becuase Dylan is
intended to be able to be compiled into a binary that doesn't have to
contain the entire interpreter and eval requires that the whole
development system is thee at runtime.
Your "${$1}" is a use of eval.
The same applies, of course, to writing this script in C, Pascal, Java or
any other traditional compiled language.
-- Bruce
Follow-Ups:
References: