Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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,
jynx


Comment on Re: (Golf) Dependency List Prioritization
Download Code
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:
    'Fubar','Bar','Baz','Foo','Foo::Bar'
    If you install them in this order, there should be no problems. An invalid ordering would be something like:
    'Fubar','Foo','Bar','Baz','Foo::Bar'
    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-12-27 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls