Solved

How to parse a template file

Posted on 1998-08-30
7
158 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pattern matching in perl 2 101
unable to remove invisible characters with perl 2 77
Using Perl to parse rows 7 93
Matching a random pattern with one common character 2 43
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.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now