'why is the hash value missing in the below code
I wanted to do a POST request to jira and jfrog. while I try to get the values of the hash within the loop am not able to get the value the second time. I try to read the variable(API token instead of password) from env, if not set it will pass the username and password.
my %urls = (
'jira' => {
'url' => 'https://jira.com:123/rest/api/2/issue/',
'token' => 'JIRA_TOKEN'
},
'jfrog' => {
'url' => 'https://jfrog.com/artifactory/api/storage/path/to/artifacts',
'token' => 'JFROG_TOKEN'
}
);
my $jira_ua = Mojo::UserAgent->new();
for my $outer_elem ( keys %urls ) {
for my $inner_elem ( keys %{$urls{$outer_elem}} ) {
# print $inner_elem;
if ( !$ENV{$urls{$outer_elem}{'token'}} ) {
print "Enter username : \n";
my $username = <STDIN>;
chomp($username);
my $passwd = read_password("Enter Password: ");
$url = Mojo::URL->new($urls{$outer_elem}->{'url'})
->userinfo($username.':'.$passwd);
}
else {
if ( $inner_elem eq "jira" ) {
$tx->req->headers->authorization (
"Bearer $ENV{$urls{$outer_elem}->{'token'}}"
);
$url = Mojo::URL->new($urls{$outer_elem}->{'url'})
}
}
print $outer_elem . "\n";
print "logging in to $urls{$outer_elem}->{'url'}\n";
$tx = my $ua->get($url); # <--- line 170
my $res = $tx->res->code;
print $res;
last;
}
}
I get below output
D:\scripts>perl emtf.pl
jira
Can't call method "get" on an undefined value at emtf.pl line 170.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
