Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:30:35+00:00 2026-06-01T16:30:35+00:00

I have this Perl script which is used to sort packages based on package

  • 0

I have this Perl script which is used to sort packages based on package version:

#!/usr/bin/perl -w
#
# Compare versions of all *.rpm files against the
# latest packages installed (if installed)
#
# Usage:
# rpmver.pl
# This script looks for all *.rpm files.
#
use strict;
use RPM2;
my $rpm_db = RPM2->open_rpm_db();
for my $filename (<*.rpm>) {
    my $h = RPM2->open_package( $filename );
    # Ensure we compare against the newest
    # package of the given name.
    my ($installed) =
      sort { $b <=> $a } $rpm_db->find_by_name($h->name);
    if (not $installed) {
        printf "Package %s not installed.\n", $h->as_nvre;
    } else {
        my ($result) = ($h <=> $installed);
        if ($result < 0) {
            printf "Installed package %s newer than file %s\n",
            $installed->as_nvre,
            $h->as_nvre;
        } else {
            printf "File %s newer than installed package %s\n",
            $h->as_nvre,
            $installed->as_nvre;
        }
    }
 } 

I have a Linux repository with SRPMs. I want to move the packages with the latest into different directory; for example latest_packages. How must the script be modified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:30:37+00:00Added an answer on June 1, 2026 at 4:30 pm

    First, store all the as-of-now-latest package names in a hash called %latest_package; then after checking all packages loop over the keys of the hash and move those latest packages.

    } else {
        printf "File %s newer than installed package %s\n", ...
        $latest_package{$h->name} = $installed->as_nvre;
        ...
    }
    

    Use File::Copy module’s move() method to move the files. Don’t forget to treat it like any other IO system call (die if it errors out including contents of $! error text variable; or use autodie).

    foreach my $name (sort keys %latest_package) {
        File::Copy::move($latest_package{$name}, $LATEST_PACKAGE_DIR) 
            || die "Could not move $latest_package{$name} to $LATEST_PACKAGE_DIR: $!);
    }
    

    Use mkdir() function to create the directory if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script, works ok: #!/usr/bin/perl $key = pack(H*,3cb37efae7f4f376ebbd76cd); $str = &4\=80CHB'; $dec
I have this Perl script sitting in the cgi-bin folder of my Apache server:
I have a perl script which is used to process some data files from
I have this conditional in a perl script: if ($lnFea =~ m/^(\d+) qid\:([^\s]+).*?\#docid =
I have one shell script opening a perl script. This perl script should be
I have a perl script that's reading an INI file like this: [placeholder_title] Hostname
I have a Perl script, that's supposed to match this string: Sometimes, he says
I have a Perl script which downloads a large number of files from a
I have the following snippet calling a perl script which writes to STDERR and
I've an annoying ASP.NET problem: I have a Perl script (see below), which gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.