On Tue, Nov 11, 2008 at 18:59, protoplasm <[EMAIL PROTECTED]> wrote: > I want to be able to search for a library that will be different on > all systems. Some places it will be libaest.so, others it will be > libaest.dylib. I cannot figure out how to do this though. I've tried > many different things and they've all resulted in failure. $search_for > contains the library I want to search for. Any pointers would be > awesome! > > find_aes_library_directory(); > > sub find_aes_library_directory { > # possible matches: libaest.dylib, libaest.1.4.0.9.dylib, > # libaest.so, libaest.so.1.4.0.9 > find_library_directory($search_for = "libaest.dylib"); > } > > sub find_library_directory { > my($lookup) = @_; > print "\nLocating directory containing $lookup...\n"; > File::Find::find(\&want_directory_parent, @library_directories); > } > > sub want_directory_parent { > my $dev = ( lstat )[ 0 ]; > ($File::Find::prune |= ($dev != $File::Find::topdev) || > ($File::Find::dir) =~ m!/\.! && return); > /^$search_for/ && push @directory_list, "$File::Find::dir"; > } >
#!/usr/bin/perl use strict; use warnings; use File::Find; print map { "$_\n" } find_aes_library_directory('/usr/lib'); sub find_aes_library_directory { # possible matches: libaest.dylib, libaest.1.4.0.9.dylib, # libaest.so, libaest.so.1.4.0.9 return find_library_directory("libaest", @_); } sub find_library_directory { my ($basefilename, @library_directories) = @_; my $re = qr/^$basefilename\.(?:[.0-9]*\.)?(?:dylib|so)$/; print "\nLocating directory containing $basefilename...\n"; my @matches; File::Find::find( sub { push @matches, $File::Find::name if /$re/ }, @library_directories ); return @matches; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/