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}~~ &nbsp; </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~~"> &raquo; ~~$french_month_name{$prev_mon +th}~~ &nbsp; </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~~"> &raquo; ~~$french_month_name{$next_mon +th}~~ &nbsp; </a> </td> </tr> </table> </div>

but not with

<div class="cell ~~$cell~~" style="background-colo +r : #f9f9f9"> <div class="date"> &nbsp; ~~$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

"There is only one good, namely knowledge, and only one evil, namely ignorance." Socrates

In reply to lost in eval and regexp by lepetitalbert

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.