Product SiteDocumentation Site

Listing tags from the package

Each RPM package has information stored under a variety of tags, such as the package name under the NAME tag and the package long description under the DESCRIPTION tag.
Cross Reference
These are the same tags introduced with the --queryformat option to the rpm command discussed in Chapter 4, Using the RPM Database .
The tag subroutine returns the value of a given tag. For example, to get the name of the package, use the NAME tag:
use RPM2;
my $header = RPM2->open_package("jikes-1.14-1-glibc-2.2.i386.rpm" );
print $header->tag("NAME"), "\n";
Pulling this together, Listing 18-1 shows example script that lists the name and one-line short summary of a package file.
Listing 18-1:
# Lists summary from an RPM package file
# Usage:
# package_name.rpm
use strict;
use RPM2;
my $header = RPM2->open_package( $ARGV[0] );
print $header->tag("NAME"), ": ", $header->tag("SUMMARY"), "\n";
Enter this script and name the file
When you run this script, you need to pass the name of a package file on the command line. For example:
$ ./ jikes-1.14-1-glibc-2.2.i386.rpm
jikes: java source to bytecode compiler