Re: [OT] Perl: exec and $variables
On Sat, Jul 21, 2001 at 01:46:25PM +0200, Joost Kooij wrote:
> On Sat, Jul 21, 2001 at 01:04:40PM +0200, Sven Burgener wrote:
> > my $BEGINREGEX = "sprintf(\"^<!-- // begin of news\$no // !-->\$\")";
>
> Please tell us what you're trying to accomplish first. It is unclear
> what assumptions you are making.
What I want is the variable $BEGINREGEX to contain a string like so:
^<!-- // begin of news1 // !-->$
or
^<!-- // begin of news2 // !-->$
The digit after the "news" should be whatever $no is set to at that
point in the script.
> > my $no = 1;
> > my $bla = eval($BEGINREGEX);
> > print "$bla\n";
> >
> > $bla is empty for some reason.
>
> You probably do not want to use eval here, or at least not in this way.
What should I do then?
It's simple, really. I am sure I am just making a stupid mistake.
my $BEGINREGEX = "sprintf(\"^<!-- // begin of news\$no // !-->\$\")";
my $no = 99;
my $bla = eval($BEGINREGEX);
print "regex string: $bla\n";
What should be printed:
regex string: ^<!-- // begin of news99 // !-->$
But it isn't, so what am I doing wrong here?
Cheers,
Sven
--
The best way to escape from a problem is to solve it.
Reply to: