Now I'm trying to figure out how I need to create my own `get_libs` sub or is there already a made basic module I should use (which probably will do a better job than me, but it should be pretty basic since it is really hard to make IT to install the module on all the machines). Looked at CPAN first and found out Devel::SharedLibs which looks like something similiar but it is not installed in IT.%libs = get_libs($path);
And then parsing the output of it. Although I'm only working on Linux SUSE, the problem is it's bad practice to parse some command's output. For example at some point, the format could change. If there was an option like `--json` or some other formatting option, to get the output as JSON and then you know how to parse it, then it would be better. But the output of `ldd` is:ldd <path>
I could parse this output like so:linux-vdso.so.1 (0x00007ffff733a000) + libems_sh.so => not found + libdl.so.2 => /lib64/libdl.so.2 (0x00007ffff7b337000) + libtq.so => not found
I really don't like my code. It feels too specific (I look for strings of -something- => -someting- -something- basically). Is it possible to review my code and suggest improvements or other ideas on how to solve this challenge?my $cmd = "ldd $path"; my ($stdout, $stderr, $exit_status) = capture { system($cmd); }; next if (exit_status); foreach my $line (split(/\n/, $stdout)) { if ($line =~ /(.*)\s*=>\s*(.*)/) { my $lib_path = $2; if ($lib_path =~ /(.*)\s+(.*)/) { $lib_path = $1; $paths{$lib_path}++; print("Found $lib_path of $path\n"); } else { print("Invalid line: $line of $path\n"); } } else { print("Invalid line: $line of $path\n"); } }
In reply to How to get all shared libs of a path? by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |