So I am trying to load test a REST API which returns a JSON value.
To do that I am creating multiple instances of the perl script.
It looks like your error message is coming from stderr, not stdout. Thus,
perl json_load_test.pl >> logs/output.txt 2>> logs/errors.txt
Or something to that effect. If you want both in one file:
perl json_load_test.pl 2>&1 >> logs/output.txt
EDIT:
If for some reason you wanted to trap the error in the perl and send it to stdout, you could:
eval {
decode_json($actual_response);
1;
} or do {
my $e = $@;
print "$e\n";
};
EDIT2:
As daxim points out in the edit notes, Try::Tiny may be simpler:
use Try::Tiny;
try {
decode_json($actual_response);
} catch {
print "$_\n";
};