HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux bareserver 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64
User: root (0)
PHP: 7.2.24-0ubuntu0.18.04.17
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //usr/share/doc/libapt-pkg-perl/examples/apt-version
#!/usr/bin/perl

#
# Example: demonstrate APT version methods
#
# Usage: apt-version compare VER1 VER2
#                    rel_compare REL1 REL2
#                    check_dep PKG OP DEP
#                    upstream VER
#

use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Version;

(my $self = $0) =~ s#.*/##;

# initialise the global config object with the default values
$_config->init;

# determine the appropriate system type
$_system = $_config->system;

# fetch a versioning system
my $vs = $_system->versioning;

print '[System: ', $_system->label, '; Versioning type: ', $vs->label, "]\n";

sub describe
{
    return 'earlier than' if $_[0] < 0;
    return 'later than'   if $_[0] > 0;
    'the same as';
}

while ($_ = shift)
{
    # compare VER1 VER2
    /^comp(?:are)?$/ and do {
	die "Usage: $self compare VER1 VER2\n" if @ARGV < 2;
	my ($ver1, $ver2) = splice @ARGV, 0, 2;
	print "* package version `$ver1' is ",
	    (describe $vs->compare($ver1, $ver2)), " `$ver2'\n";

	next;
    };

    # rel_compare REL1 REL2
    /^rel(?:[_-]comp(?:are)?)?$/ and do {
	die "Usage: $self rel_compare REL1 REL2\n" if @ARGV < 2;
	my ($ver1, $ver2) = splice @ARGV, 0, 2;
	print "* release version `$ver1' is ",
	    (describe $vs->rel_compare($ver1, $ver2)), " `$ver2'\n";

	next;
    };

    # check_dep PKG OP DEP
    /^check(?:[_-]dep)?$/ and do {
	die "Usage: $self check_dep PKG OP DEP\n" if @ARGV < 3;
	my ($pkg, $op, $dep) = splice @ARGV, 0, 3;
	my $r = $vs->check_dep($pkg, $op, $dep) ? 'satisfies'
		    : 'does not satisfy';

	print "* package version `$pkg' $r the dependency `($op $dep)'\n";
	next;
    };

    # upstream VER
    /^upstream$/ and do {
	die "Usage: $self upstream VER\n" if @ARGV < 1;
	my $ver = shift;
	print "* upstream component of package version `$ver' is `",
	    $vs->upstream($ver), "'\n";

	next;
    };

    die "$self: unknown action `$_'\n";
}