lepetitalbert has asked for the wisdom of the Perl Monks concerning the following question:
Hi dear Monks
As I'd like to create a easy to install cgi script ( no HTML::Template), I try to write a very simple 'replace' sub, to load a html and replace some variables.
sub replace { my $file = shift; open FILE , $file or die "oups"; my @BUFFER = <FILE> and close FILE; my @OUT_BUFFER; foreach my $line ( @BUFFER ) { if ( $line =~ /~~/ ) { my @SPLITTED = split( /~~/ , $line ); foreach ( @SPLITTED ) { if ( $_ =~ /\$/ ){ my $tmp = eval $_; $line =~ s/~~\$.*~~/$tmp/; } } } push ( @OUT_BUFFER , $line ); } print @OUT_BUFFER; }
this works with :
~~$french_month_name{$month}~~ 20~~$year~~ </td> <td colspan="2" align="right"> <div id="date"> ~~$today_day_name~~ ~~$today_day_display_number~~ ~~$french_month_name{$today_month_numb +er}~~ </div> </td> </tr> <tr> <td class="titlebar1"> </td> <td class="titlebar2" width="80px" align="righ +t"> <a class="white" href="~~$cgi_dir~~ /agenda.pl?user= ~~$user~~&month= ~~$prev_month~~&year= ~~$down_link_year_num~~"> » ~~$french_month_name{$prev_mon +th}~~ </a> <td class="titlebar2" width="80px" align="righ +t"> <a class="white" href="~~$cgi_dir~~ /agenda.pl?user= ~~$user~~&month= ~~$next_month~~&year= ~~$up_link_year_num~~"> » ~~$french_month_name{$next_mon +th}~~ </a> </td> </tr> </table> </div>
but not with
<div class="cell ~~$cell~~" style="background-colo +r : #f9f9f9"> <div class="date"> ~~$day_prev_month~~ </div> </div>
And I don't understand why.
The replace sub is in a loop, maybe an out of scope problem ?
If somebody has the exact regexp for ~~$year~~ and ~~$french_month_name{$month}~~ ?
And if somebody has a solution I could use multiple ~~*~~ on one line
Thank you and ...
Have a nice day
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: lost in eval and regexp
by ikegami (Patriarch) on Nov 21, 2007 at 15:00 UTC | |
by lepetitalbert (Abbot) on Nov 21, 2007 at 16:06 UTC | |
by ikegami (Patriarch) on Nov 21, 2007 at 18:20 UTC | |
by lepetitalbert (Abbot) on Nov 21, 2007 at 17:02 UTC | |
Re: lost in eval and regexp
by gamache (Friar) on Nov 21, 2007 at 14:38 UTC | |
by ikegami (Patriarch) on Nov 21, 2007 at 14:52 UTC | |
Re: lost in eval and regexp
by toolic (Bishop) on Nov 21, 2007 at 14:44 UTC |