For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > Getting the values of some variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Getting the values of some variables
Octavian Rasnita

2004-05-22, 11:31 am

Hi all,

I have a text file that contains a text something like this:

This text contains a $aa variable and a $bb variable and a $cc one.

My program reads this text and I want to replace the variables with their
values, then return the result string.

How can I do this?

Is using s/(\$\w+)/eval($1)/gse the only solution?
(I haven't test it if it works this way yet, but I hope there is a simpler
and easier method to evaluate the entire string.
Is there such a way?

Thank you.

Teddy

Frbn

2004-05-22, 11:31 am

do you use double quotes to interpolate the string ?


Octavian Rasnita wrote:

>Hi all,
>
>I have a text file that contains a text something like this:
>
>This text contains a $aa variable and a $bb variable and a $cc one.
>
>My program reads this text and I want to replace the variables with their
>values, then return the result string.
>
>How can I do this?
>
>Is using s/(\$\w+)/eval($1)/gse the only solution?
>(I haven't test it if it works this way yet, but I hope there is a simpler
>and easier method to evaluate the entire string.
>Is there such a way?
>
>Thank you.
>
>Teddy
>
>
>
>

Charles K. Clarkson

2004-05-22, 11:31 am

Octavian Rasnita <orasnita@fcc.r> wrote:
:
: I have a text file that contains a text something like
: this:
:
: This text contains a $aa variable and a $bb variable
: and a $cc one.
:
: My program reads this text and I want to replace the
: variables with their values, then return the result
: string.
:
: How can I do this?
:
: Is using s/(\$\w+)/eval($1)/gse the only solution?
: (I haven't test it if it works this way yet, but I hope
: there is a simpler and easier method to evaluate the
: entire string.
: Is there such a way?

Octavian,

Have you looked at Text::Template? It does this (and some more)
but it requires delimiters around the variables.

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


Octavian Rasnita

2004-05-22, 11:31 am

How can I do that?

I have the string in $in variable and it contains the text:

"example $aa $bb $cc ..."

Thanks.

T

----- Original Message -----
From: "frbn" <frbn@efbs-seafrigo.fr>
To: "Octavian Rasnita" <orasnita@fcc.ro>
Cc: <beginners-cgi@perl.org>
Sent: Thursday, April 15, 2004 5:47 PM
Subject: Re: Getting the values of some variables

[color=darkred]
> do you use double quotes to interpolate the string ?
>
>
> Octavian Rasnita wrote:
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com