Using a variable with gsub & sub

P

Peter Vanderhaden

In the following statement, I'm replacing ,, with ,NULL,.

$inrec = $inrec.sub(',,\\',',NULL,')

What I want to do is something like this:

$inrec = $inrec.sub(',,\\',',$variable,')

Unfortunately, I haven't been able to figure out the syntax for using a
variable with sub & gsub. Can someone help me out?
Thanks.
 
Y

yermej

In the following statement, I'm replacing ,, with ,NULL,.

$inrec = $inrec.sub(',,\\',',NULL,')

What I want to do is something like this:

$inrec = $inrec.sub(',,\\',',$variable,')

Unfortunately, I haven't been able to figure out the syntax for using a
variable with sub & gsub. Can someone help me out?

$inrec.gsub! ',,\\', ",#{$variable},"

Though I'm not sure why you have the \\ in there, unless it just
didn't end up on the newsgroup correctly.
 
H

Harry Kakueki

What I want to do is something like this:

$inrec = $inrec.sub(',,\\',',$variable,')

Unfortunately, I haven't been able to figure out the syntax for using a
variable with sub & gsub. Can someone help me out?

Try this.

",#{var},"

Harry
 
P

Peter Vanderhaden

yermej,
Your solution was exactly what I needed, thanks. As for the \\, that is
part of the first value that is being replaced. The first backslash is
an escape character for the second backshash.
Thanks again,
PETERV
 
J

Justin Collins

Peter said:
yermej,
Your solution was exactly what I needed, thanks. As for the \\, that is
part of the first value that is being replaced. The first backslash is
an escape character for the second backshash.
Thanks again,
PETERV
If you really want to use global variables ($var) then you can also do

$inrec.gsub!(',,\\', ",#$variable,")
 

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

Forum statistics

Threads
473,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top