I also saw a video about how the JSON module in Perl is quite slow, could that be it?
No, because you are not using the JSON module, you are using the JSON::XS module. The two are quite different and the latter is purposely much faster than the former. And even if it weren't we are not talking about a particularly large chunk of JSON to decode.
I have not profiled your Perl code because as posted it fails to compile:
Missing right curly or square bracket at 11162986.pl line 36, at end o +f line syntax error at 11162986.pl line 36, at EOF 11162986.pl had compilation errors.
While I can guess what is wrong, this shows that the code you have posted is not the code you are running, so who knows what else might actually be in there to slow it down.
Regardless, a fair guess would be that the slow part is this line:
my $result = qx{ i3-msg -t get_workspaces }; # returns [{},{},{}]
Shelling out 100 times is going to be slow however you do it. Try obtaining the JSON once and then loop 100 times over the rest of the processing and see what difference that makes.
🦛
In reply to Re: Adjusting variable context when working with JSON data?
by hippo
in thread Adjusting variable context when workign with JSON data?
by unmatched
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |