in reply to Re: Using . in variable name
in thread Using . in variable name

Thanks everyone for the quick responses but that's the thing, I do not have access to the script. I have just been asked to pass it as $app1.svr which I am not able to do from Perl.

If this doesn't work out, I will have to rewrite my code in another language, which I am hesitating to do.

Anyways, as you mentioned, it's not possible so I might as well start exploring other options.

Replies are listed 'Best First'.
Re^3: Using . in variable name
by Corion (Patriarch) on Apr 17, 2015 at 07:13 UTC

    Maybe I didn't understand the problem as you stated it.

    Can you maybe take a step back and tell us the problem you're trying to solve? If you're calling another script, that script is likely invoked via system or exec. Maybe you don't want to use a variable name but a variable value?

    You can append a value to a string by using dot itself, or by using double quotes:

    print "$app.svr\n"; print $app . ".svr\n";

      Or a parameter name, e.g. (for the OP):

      system("myotherscript $app1.svr=3 $somevar=27");
        Double quotes interpolate variables. This would therefore replace $app1 with the contents of the $app1 variable.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thank you for all the help again. Here's the code that invokes the script:

      system("ant -file japi/test.xml -Dapp1.url=${app1.url} -Dapp2.url=${app2.url}");

        You can call the variable anything. Let's say $dog or $cat in which case:

        my $dog = 'http://www.perl.org/'; my $cat = 'https://metacpan.org/'; system("ant -file japi/test.xml -Dapp1.url=$dog -Dapp2.url=$cat");

        Which is equivalent then to this command you would type at your prompt:

        ant -file japi/test.xml -Dapp1.url=http://www.perl.org/ -Dapp2.url=htt +ps://metacpan.org/

        Maybe you don't want to use a variable here but a hash with the appropriate keys?

        Or just change ${app1.url} to $app1_url if you feel uncomfortable with hashes?