in reply to How to pass variable in the LWP module

I agree with others that your basic problem seems to be a lack of understanding of string interpolation. In the OPed code, you seem to be trying to include a single-quote literal character in a single-quoted string, and also to interpolate a variable into a single-quoted string (such strings do not interpolate).

Here are two possible approaches to what seem to be your problems. The first, which I prefer, uses double-quote interpolation along with properly chosen quote delimiters. The second uses explicit string concatenation.

c:\@Work\Perl\monks>perl -wMstrict -le "my $location_id = 'Kansas'; ;; my $string = qq{{\"category\"->'$location_id'}}; print qq{:$string:}; ;; $location_id = 'OverTheMoon'; ;; $string = '{\"category\"->\'' . $location_id . '\'}'; print qq{:$string:}; " :{"category"->'Kansas'}: :{"category"->'OverTheMoon'}:

Note that because I am giving you a Windows command-line code example, I have to escape all the double-quote literal characters in the code. You do not have to bother with this annoyance. Also note that the second code example, of explicit concatenation, has some single-quote characters that are escaped. You do need the escapes in these cases.

Please see Quote and Quote-like Operators. Also see the  . (concatenation) operator in Additive Operators in perlop. (Update: Actually, the latter link isn't terribly informative!)


Give a man a fish:  <%-(-(-(-<