in reply to More Effecient Method Chaining

You shell out multiple times. The performance of the Perl code seems inconsequential.

This post will cover some cleanups (but leaves the important question of parallelism unanswered).


I don't think

map { $1 if /^\w+:\s+(\w+)\b/ }

has a defined behaviour. You want

map { /^\w+:\s+(\w+)\b/ }

And the grep { /^\w+:/ } is completely redundant.


Backticks returns the captured output as lines in list context, so

split /\n/, `gst-inspect-1.0`

can be replaced with

`gst-inspect-1.0`

It's not equivalent since it leaves the line feeds in, but that's not an issue for you.


Cleaned:

my %plugins = map { $_ => scalar `gst-inspect-1.0 $_` } map { /^\w+:\s+(\w+)\b/ } `gst-inspect-1.0`;
You could even combine the two maps, but I wouldn't.
my %plugins = map { /^\w+:\s+(\w+)\b/ ? $1 => scalar `gst-inspect-1.0 $1` : () } `gst-inspect-1.0`;

Seeking work! You can reach me at ikegami@adaelis.com

Replies are listed 'Best First'.
Re^2: More Effecient Method Chaining
by perlfan (Vicar) on Apr 22, 2021 at 05:11 UTC
    > shell out
    Concur, dr. If this external "binary" is a perl program, OP is committing great shame in not at least crafting a modulino and using the functionality in the same process as a simple library call.

      > shell out Concur, dr. If this external "binary" is a perl program, OP is committing great shame in not at least crafting a modulino and using the functionality in the same process as a simple library call.

      it is shameful to call shame

      or promote modulino