in reply to Re^3: Regular expression match and substitution
in thread Regular expression match and substitution

$sym{'$b'} is already defined.

my $p = "$sym{'$b'}/helloworld/test.dat"; $sym{'$b'} = "my"; my $val = eval $p; print "p = $val\n";

This doesn't work as it should.

-P

Replies are listed 'Best First'.
Re^5: Regular expression match and substitution
by ikegami (Patriarch) on Nov 09, 2004 at 21:35 UTC

    For starters, my/helloworld/test.dat is not valid Perl. (bare word my divided by bare word helloworld divided by bare word test concatenated with bare word dat?) So add quotes.

    Two, you want the $vars to be in $p instead of being interpolated, so use single quotes or escape the $ (and any @) in the literal.

    my $p = "\"\$sym{'\$b'}/helloworld/test.dat\""; # my $p = 'qq[$sym{'$b'}/helloworld/test.dat]'; # alternative # my $p = '"$sym{\'$b\'}/helloworld/test.dat"'; # alternative # my $p = q["$sym{'$b'}/helloworld/test.dat"]; # alternative $sym{'$b'} = "my"; my $val = eval $p; print "p = $val\n";