DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Parse Solaris Pkginfo -l In Perl
// description of your code here
#!/usr/bin/perl -w
#
#
#
use strict;
use Data::Dumper;
my $pkg_list = "/usr/bin/pkginfo -l|";
open (PKG_LIST, $pkg_list) || die "Can't run '$pkg_list': $!\n";
my $pkg;
while (defined (my $line = <PKG_LIST>)) {
chomp $line;
my $match = ( $line =~ /PKGINST:/ .. $line =~ /^$/ );
if ( $match && $match !~ /E0/ ) {
if ( $line =~ /^\s+([A-Z]+):\s+(.*)$/ ) {
my ($key, $val) = ($1, $2);
if ( $key eq 'FILES' ) {
if ( $val =~ /^(\d+) (.*)$/ ) {
$pkg->{FILES}->{$2} = $1;
}
}
else {
$pkg->{$1} = $2;
}
}
elsif ( $line =~ /^\s+([0-9]+) (.*)$/ ) {
$pkg->{FILES}->{$2} = $1;
}
else {
print "Unrecognized output: [$line]\n";
}
}
else {
#
# Blank line between packages
#
print Dumper $pkg;
}
}
close PKG_LIST;





