Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: More Effecient Method Chaining

by ikegami (Patriarch)
on Apr 21, 2021 at 22:20 UTC ( [id://11131561]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131561]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-24 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found