On Sat, Mar 14, 2009 at 18:04, Chap Harrison <c...@pobox.com> wrote:
> I want to compute a file pathname based on a "template" at runtime, when I
> know the value of a variable that the template uses.
>
> In other words, the template for the path name looks like this...
>
> /foo/bar/$project/here
snip
> I've read perldoc on 'eval', and googled a bit, but no joy.
snip

String eval is bad mojo.  What you really need is either a template
module* (if your needs are very complex) or a simple substitution (if
you needs are simple).

#!/usr/bin/perl

use strict;
use warnings;

my $project_path_template = "/foo/bar/{PROJECT}/here";

for my $project (qw/project1 project2 project3/) {
        (my $project_path = $project_path_template) =~ s/\{PROJECT\}/$project/;
        print "the project path is $project_path\n";
}

* Search CPAN for template modules until you find one with the
features you want, this one looks fairly close to what you want:
http://search.cpan.org/dist/Text-Template/lib/Text/Template.pm

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to