CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
change the single quoted string to double quoted string so that the variables are interpreted

 



sankar_sankar
Novice

Mar 22, 2006, 10:48 PM

Post #1 of 3 (362 views)
change the single quoted string to double quoted string so that the variables are interpreted Can't Post

Hi,

in my program, i will receive a $key from a method like

$key = getKey();

#the function

sub getkey()

{

.........................#some code

return '$col1,$col2,$col3';

}

now in my program i had these variables $col1 $col2 and $col3. so now how can i change the single quoted string to double quoted string so that the variables are interpreted automatically.

please some one help me!

thanks


KevinR
Veteran


Mar 22, 2006, 11:24 PM

Post #2 of 3 (361 views)
Re: [sankar_sankar] change the single quoted string to double quoted string so that the variables are interpreted [In reply to] Can't Post

quoted from the Perl CookBook:


Quote
1.8. Expanding Variables in User Input
Problem

You've read in a string with an embedded variable reference, such as:

You owe $debt to me.

Now you want to replace $debt in the string with its value.
Solution

Use a substitution with symbolic references if the variables are all globals:

$text =~ s/\$(\w+)/${$1}/g;

But use a double /ee if they might be lexical (my) variables:

$text =~ s/(\$\w+)/$1/gee;

-------------------------------------------------


sankar_sankar
Novice

Mar 23, 2006, 6:20 AM

Post #3 of 3 (356 views)
Re: [KevinR] change the single quoted string to double quoted string so that the variables are interpreted [In reply to] Can't Post

thanks, this will solve my problem....

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives