Substitution with parameters and variable don't works/$search/$replace/i

  • Thread starter Joan Interactive Bussiness
  • Start date
J

Joan Interactive Bussiness

Very easy sample:

# line to translate
$line = 'var varchar2(10)';

# I hope to answer: var number(10)

# With replace Variable, not OK
$find = 'varchar2\((.+)\)';
$replace = 'number($1)';

$line =~ s/$find/$replace/;
print $line."\n";
# result >>>>>> var number($1)


# Without replace Variable, it's OK
$line2 = 'var varchar2(10)';
$line2 =~ s/varchar2\((.+)\)/number($1)/;
print $line2."\n";
# result >>>>>> var number(10)

# ----------------------------------------
P:\DB\WORK\perl>perl test.pl
var number($1)
var number(10)
 
S

sln

# line to translate
$line = 'var varchar2(10)';

# I hope to answer: var number(10)

# With replace Variable, not OK
$find = 'varchar2\((.+)\)';
$replace = '"number($1)"';

$line =~ s/$find/$replace/ee;


Here we go again..
-sln
 
K

Kyle T. Jones

Joan said:
Very easy sample:

# line to translate
$line = 'var varchar2(10)';

# I hope to answer: var number(10)

# With replace Variable, not OK
$find = 'varchar2\((.+)\)';
$replace = 'number($1)';

You're using single quotes '' instead of double quotes "" so the
variable ($1) isn't being interpolated. If you're using variables or
special characters (like \n) you need to use double-quotes.

my $name="Joe";
print "$name is a genius.\n";
print "He loves perl.\n";

Output:

Joe is a genuis.
He loves perl.

my $name='Joe';
print '$name is a genius.\n';
print 'He loves perl.\n';

Output:

$name is a genius.\nHe loves perl.\n

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top