Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > a problem with variable interpolation..

Thread Tools

a problem with variable interpolation..

Posts: n/a

# heres a peice of script which is troublin me since a while. Might as
well be # a newbee question!! The problem is,
# upon single quoting the $sentence ( see below) , and forcing
# by putting it in double quotes while printing, the string simply
# not get evaluated as no evaluation is specified during its

# upon forcing evaluation by defining $sentence in double quotes, the
# compiler evaluates it as a system path, and does not interpolate the

# Is there a workaround which would enable evaluation of variables,
# evaluating it as a path?
# and thus hopefully print '\dhdu\foo\sdjadf\bar\edjd\huh' ?

$var1 = 'foo';
$var2 = 'bar';
$var3 = 'huh';

$sentence = "\dhdu\$var1\sdjadf\$var2\edjd\$var3";

print "$sentence";
Reply With Quote
Tore Aursand
Posts: n/a
On Sun, 10 Oct 2004 23:13:35 -0700, Kevin wrote:
> #!/opt/perl_5.8.5/bin

Remember these:

use strict;
use warnings;

> $var1 = 'foo';
> $var2 = 'bar';
> $var3 = 'huh';
> $sentence = "\dhdu\$var1\sdjadf\$var2\edjd\$var3";

The '\' will escape anything that comes right after it. You probably want
to escape the '\' character itself, or use the '/' character instead
(which works just fine on multiple platforms).

Tore Aursand <(E-Mail Removed)>
"When you love someone, all your saved-up wishes start coming out."
(Elizabeth Bowen)
Reply With Quote
Jürgen Exner
Posts: n/a
Kevin wrote:
> $var1 = 'foo';
> $var2 = 'bar';
> $var3 = 'huh';
> $sentence = "\dhdu\$var1\sdjadf\$var2\edjd\$var3";
> print "$sentence";

See "perldoc -q DOS":
Why can't I use "C:\temp\foo" in DOS paths? What doesn't
`C:\temp\foo.exe` work?

On top of that you are escaping the dollar signs, thereby explicitely
telling perl to _not expand the variables $var1, ...


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
assign JavaScript variable to Java variable problem in JSP Matt Java 8 01-25-2010 04:48 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
Convert Character Variable to Integer Variable Brad Smallridge VHDL 2 11-18-2004 01:56 AM
assign JavaScript variable to Java variable problem in JSP Matt Javascript 2 09-26-2004 06:12 AM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM