in reply to Re: Parsing a string from a file
in thread Parsing a string from a file

Many thanks!
*will remember eval for future use* :D
And about the integrity of the data, I'm inputting it myself in these text files :D
Again, thanks!

Replies are listed 'Best First'.
Re^3: Parsing a string from a file
by davidrw (Prior) on Jun 11, 2005 at 18:29 UTC
    Ah, so these are self-created data files? In that case (since you can format the data any way you want) you may want to consider using an existing template solution like Template Toolkit. This way you don't need to worry about eval or anything like that, plus you gets tons of other functionality.
    my @time = (1, 2, 3); my $counter = 5; my $data = { counter => $counter, time => \@time, }; my $s = 'Today is [% time.1 %] and you have seen this [% counter %] ti +me[% "s" IF counter > 1 %]!'; warn $s; use Template; my $template = Template->new(); my $out = ''; $template->process(\$s, $data, \$out) or die $template->error; warn $out; __END__ ~~~Output~~~: Today is [% time.1 %] and you have seen this [% counter %] time[% "s" +IF counter > 1 %]! at /tmp/t line 8. Today is 2 and you have seen this 5 times! at /tmp/t line 13.