As Hippo said:

Your question was how to use $location_id outside the box (the scope in which it was declared; your sub, or if statement...)

But you have a separate problem which is that you declare my $location_id twice. As Hippo said, you should always use warnings; at the top of your script, and perl will tell you about these errors. You must only declare a variable once.

When you have declared it with my $location_id, it will stay in existence until the end of your scope. If you have a "box" after you declare the variable, the variable will be available in the "box," and again once you exit the "box," reflecting any changes you made to its value inside the "box."

use strict; use warnings; my $location_id = 'foo'; if ($resp->is_success) { # the box? $location_id = 'bar'; } say $location_id; # prints 'bar'

In reply to Re: how to get the local variable value outside the box by 1nickt
in thread how to get the local variable value outside the box 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.