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:  <%-(-(-(-<


In reply to Re: How to pass variable in the LWP module by AnomalousMonk
in thread How to pass variable in the LWP module by bhushanQA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.