freak022398
asked on
How to parse a template file
How do i read a template file like this:
<IMG SCR=$pic.jpg>
<A HREF="$link">$text</A>
The $pic, $link and $text vars shouldt be changed to the
values they have in my perl program.
I have tried to read a file, line by line. And then use the
eval(); function, but that does not work :(
Please help me!
Regards Martin Møller.
<IMG SCR=$pic.jpg>
<A HREF="$link">$text</A>
The $pic, $link and $text vars shouldt be changed to the
values they have in my perl program.
I have tried to read a file, line by line. And then use the
eval(); function, but that does not work :(
Please help me!
Regards Martin Møller.
ASKER
I can't get that to work :(
Or i don't know where to put it!
I have my template file in @temp, and i'm trying something like this:
foreach $tmp (@temp) {
# This is where i need to find all $pic, $link, etc in $tmp.
# and then insert the correct value i at that place.
print "$tmp<BR>\n";
}
So how do i use you'r code within my foreach loop?
Regards. Martin Møller.
Or i don't know where to put it!
I have my template file in @temp, and i'm trying something like this:
foreach $tmp (@temp) {
# This is where i need to find all $pic, $link, etc in $tmp.
# and then insert the correct value i at that place.
print "$tmp<BR>\n";
}
So how do i use you'r code within my foreach loop?
Regards. Martin Møller.
$tmp =~ s/(\$\w+)/$1/eeg;
ASKER
It still won't work!
This code:
$testa = "testing";
$test = 'test=$testa';
print "$test<BR>";
$test = ~s/(\$\w+)/$1/eeg;
print "$test<BR>";
makes this output:
test=$testa
4294967295
Where does that number come from? what an i doing wrong?
Martin Møller.
This code:
$testa = "testing";
$test = 'test=$testa';
print "$test<BR>";
$test = ~s/(\$\w+)/$1/eeg;
print "$test<BR>";
makes this output:
test=$testa
4294967295
Where does that number come from? what an i doing wrong?
Martin Møller.
that's «=~» not «= ~»
ASKER
Great, thats it!
Now send an answer so you can get you'r points :)
Regards. Martin Møller.
Now send an answer so you can get you'r points :)
Regards. Martin Møller.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
s/(\$\w+)/$1/eeg;
print;
}