Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: (Golf) Dependency List Prioritization

by jynx (Priest)
on Mar 13, 2002 at 22:49 UTC ( #151545=note: print w/replies, xml ) Need Help??

in reply to (Golf) Dependency List Prioritization

For those of us not in the know,

can you please list a solid example input and output and give the reasons why the output is associated with the input? Looking at what you have, it doesn't look like that sample output would be matched with that input, but it could be. And if it was, i would have no idea why, as i've never dealt with such lists before. Also i haven't installed PSI::ESP so i don't know what you mean by 'ordered by precedence'.

Please advise,

Replies are listed 'Best First'.
Re^2: (Golf) Dependency List Prioritization
by tadman (Prior) on Mar 13, 2002 at 23:12 UTC
    Maybe a little more verbosity would help.

    To speak in terms of Perl, if you have a module Foo which requires module Bar to operate, then there is a dependency. Bar must be installed before Foo. In some cases, such as with RPM, you just can't install Foo until Bar is in place. With Perl, you can install Foo, but it will fail, as it is missing its beloved Bar, and your program won't run.

    Maybe Foo also needs the module Baz to run, so that is a second dependency. If you also had a Foo::Bar module, which needed Foo, then you have a second dependency. Perhaps Bar also needs something, say, Fubar, to do its thing.

    This leads to a dependency structure that looks like this:
    my %dep = ( 'Foo' => [ 'Bar','Baz' ], 'Foo::Bar' => [ 'Foo' ], 'Bar' => [ 'Fubar' ], );
    Now the idea is to, based on this specification, figure out what order they can be installed in such that each module is only installed when all of its dependencies are satisfied. One such order is:
    If you install them in this order, there should be no problems. An invalid ordering would be something like:
    In this case Foo does not have either Bar or Baz available, so it can't work. Foo must come after both Bar and Baz.

    To answer a question, the order of the dependencies is not relevant. If Foo requires Bar and Baz, you can list Bar and Baz in any order. After all, they just have to be present and accounted for. Apart from that, nothing else matters. This means that the following are equivalent:
    'a' => [ 'b','c' ] 'a' => [ 'c','b' ]
    These both specify that 'a' requires 'b' and 'c'. It's like saying that a 'car' needs 'gas' and 'tires' to run. As long as you have both, you're good to go. Procedure is irrelevant, as you're not going anywhere until both are present anyway.

    What's interesting about this problem is that at first, it seems quite difficult to solve, but with a bit of creative thinking it was really straightforward. It seems to be a matter of perspective.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://151545]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-05-21 21:50 GMT
Find Nodes?
    Voting Booth?