Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: Make vs. Perl

by Fastolfe (Vicar)
on Nov 15, 2000 at 21:44 UTC ( [id://41810]=note: print w/replies, xml ) Need Help??


in reply to Make vs. Perl

If you're looking for generic dependency-handling code (there are Perl implementations of 'make' I believe; don't re-invent the wheel), something recursive like this might work for you:
my %dependencies = ( item1 => [ 'item2' ], item2 => [ qw' item3 item4 ' ], ); my %done; sub act_on { my $item = shift; $done{$item} = undef; # mark it early to avoid circular dependen +cies if (exists $dependencies{$item}) { foreach my $dep (@{$dependencies{$item}}) { warn "Circular dependency $item => $dep" if exists $done{$dep} and !$done{$dep}; &act_on($dep) unless exists $done{$dep}; } } # Dependencies satisfied, do whatever on $item print "Doing $item...\n"; $done{$item} = 1; # really done } act_on "item1"; Doing item3... Doing item4... Doing item2... Doing item1...
Change the function name around if you like to make it more idiomatic if that's what you're looking for...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found