in reply to how to get the local variable value outside the box
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'
|
|---|