|
Posted by technut666 on April 17, 2008, 11:23 am
Please log in for more thread options >
>
>
>
> > > Hi,
>
> > > I have a script where I define a string at the top of the file.
> > > The string includes a variable which is not set until later in the
> > > script. As a result the variable is evaluated as null and does not
> > > appear in the string.
> > > Is there a way to say to the Perl interpreter - do not evaluate the
> > > string defined at the start, but wait until it is used?
>
> > > Code sample:
>
> > > my $LANG_LOCALE; # defined, but null value
>
> > > my $ERROR_MSG_BUILDVER_INI_MISSING = "BuildVer.ini file for service
> > > not found at $_TOP/services/imApp/$LANG_LOCALE";
>
> > > function show_message(){
> > > $LANG_LOCALE = "de-DE";
> > > print "$ERROR_MSG_BUILDVER_INI_MISSING";
>
> > > }
>
> > To do your function, just remove the quotes
> > so the variable is evaluated inside the function:
>
> > function show_message(){
> > $LANG_LOCALE = "de-DE";
> > print $ERROR_MSG_BUILDVER_INI_MISSING;
>
> > }
>
> > To answer your more general question, there is
> > no such thing as "defining" a string. You were
> > making an assignment, which does the evaluation
> > of the expression. If you really want to evaluate
> > an expression later, look at the eval function.
> > --S
>
> Sorry. Meant to move the expression inside the
> function, of course, not just the variable.
Hi,
Thanks for you response! :D
The code sample was to just illustrate the issue - there is more going
on here.
Basically I have to declare a bunch of error messages at the start of
the script.
I then read in a file with a bunch of environment settings - one of
which is $lang_locale. So I can't know $lang_locale until after I
have declared the error messages. (Again a simplified description of
what is going on in the script :D )
|