Solved

How to parse a template file

Posted on 1998-08-30
7
188 Views
Last Modified: 2010-03-05
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.
0
Comment
Question by:freak022398
  • 4
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1204602
while( <> ){
    s/(\$\w+)/$1/eeg;
    print;
}
0
 

Author Comment

by:freak022398
ID: 1204603
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.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1204604
$tmp =~ s/(\$\w+)/$1/eeg;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:freak022398
ID: 1204605
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.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1204606
that's «=~» not «= ~»
0
 

Author Comment

by:freak022398
ID: 1204607
Great, thats it!
Now send an answer so you can get you'r points :)

Regards. Martin Møller.

0
 
LVL 84

Accepted Solution

by:
ozo earned 130 total points
ID: 1204608
$test =~ s/\$(\w+)/${$1}/g;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 99
crawling gofundme 4 145
Having a problem with ActiveState Perl on 64-bit Windows 7 3 77
File Find regex problem 4 68
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question