kviki_kiki has asked for the wisdom of the Perl Monks concerning the following question:

Hello there,

you were very kind the first time I posted a question, so I hope someone will know the answer to my problem

.

I have a perl script that needs to make a php page. I am making a php page because I need it to be password protected. The thing is, each time there is a $ character, perl does not write it into the php file, nor the name associate with it. For example:

$LOGIN_INFORMATION = array('guest' => '1234');

it looks like this in php:

= array('guest' => '1234');

Could you please tell me how to solve this?

Thank you!

Replies are listed 'Best First'.
Re: "Translating" $
by choroba (Cardinal) on Oct 01, 2015 at 12:42 UTC
    You probably used strings in double quotes. Perl interpolates (scalar and array) variables in double quotes. You can
    1. use single quotes '$LOGIN_INFORMATION = array("guest" => "1234");'
    2. use the q// operator: q/$LOGIN_INFORMATION = array('guest' => '1234');/
    3. backslash the dollar sign (and at signs): "\$LOGIN_INFORMATION = array('guest' => '1234');"
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thank you so very much for your help! Your advice with \ worked perfectly :)

Re: "Translating" $
by GotToBTru (Prior) on Oct 01, 2015 at 12:45 UTC

    Perl is doing what you ask. $LOGIN_INFORMATION is the name of a variable and it is interpolating the variable, substituting the value in your string. If you had put

    use strict; use warnings;

    at the beginning of your script, you would be informed that you're using an undeclared variable, and that might have helped you figure this out yourself. In order to convince Perl that it should print $LOGIN_INFORMATION just like that, you need to either escape the $ or print using single quotes.

    print "\$LOGIN_INFORMATION ... or print '$LOGIN_INFORMATION = array(\'guest\' => \'1234\');';

    UPDATE: I like choroba's q// approach best.

    or print q/$LOGIN_INFORMATION = array('guest' => '1234');/;
    Dum Spiro Spero
Re: "Translating" $
by hippo (Archbishop) on Oct 01, 2015 at 14:38 UTC
    I am making a php page because I need it to be password protected.

    Not sure why you think that password protection requires the use of PHP. A Perl script can quite happily be password protected. If you provide some more detail about the security you are trying to deploy we could probably advise on a simple alternative which would eliminate the need for PHP entirely.

Re: "Translating" $
by Corion (Patriarch) on Oct 01, 2015 at 12:41 UTC

    How do you create the output?

    Most likely, you want to add use strict; to the top of your program so that Perl can alert you when you use variables that you have not declared before.

    You might also want to investigate the difference between single and double quotes in Perl code.