Hello Monks!
This question is more sort of a code-review. I'll explain what I'm trying to do.
I'm using Linux env. I'm looking for a way to get all shared libraries of path. So basically something like:
%libs = get_libs($path);
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.
The way I thought of implementing the `get_libs` sub is by using:
ldd <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:
linux-vdso.so.1 (0x00007ffff733a000) + libems_sh.so => not found + libdl.so.2 => /lib64/libdl.so.2 (0x00007ffff7b337000) + libtq.so => not found
I could parse this output like so:
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"); } }
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?

In reply to How to get all shared libs of a path? by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.