ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: mookid@sigent.ru (Mikhail Zabaluev)
To: devel@linux.iplabs.ru
Subject: Re: [devel] Q: perl
Date: Wed, 20 Dec 2000 02:35:12 +0300
Message-ID: <20001220023512.B1252@localhost.localdomain> (raw)
In-Reply-To: <3A3FD5B2.4020905@logic.ru>; from aen@logic.ru on Wed, Dec 20, 2000 at 12:40:02AM +0300

Hello Aleksey,

On Wed, Dec 20, 2000 at 00:40 +0300, Aleksey Novodvorsky wrote:
>
> Господа, я уже почти привык к perl'у, но все же будет лучше, если эту 
> функицю перепишет кто-нибудь из знатоков.
> sub version_compare {
>    my ($a, $b) = @_;
>    local $_;
> 
>    while ($a || $b) {
>        my ($sb, $sa) =  map { $1 if $a =~ /^\W*\d/ ? s/^\W*0*(\d+)// : 
> s/^\W*(\D+)// } ($b, $a);
>        $_ = length($sa) cmp length($sb) || $sa cmp $sb and return $_;
>    }
> }
> 
> Дело в том, что она неверно (точнее -- не так, как хотелось бы) 
> сравнивает названия полей release в том случае, если там есть ipl.

Вот функция по мотивам файла 'dependencies' из документации rpm:

sub version_compare {
    my ($a, $b) = @_;
    local $_;

    while ($a || $b) {
        my ($sa, $sb);
        if ($a =~ /^[\W_]*\d/ && $b =~ /^[\W_]*\d/) {
            ($sa, $sb) = map { s/^[\W_]*0*(\d+)//; $1 } ($a, $b);
            $_ = length($sa) cmp length($sb) || $sa <=> $sb and return $_;
        } elsif ($a =~ /^[\W_]*(\D|$)/ && $b =~ /^[\W_]*(\D|$)/) {
            ($sa, $sb) = map { s/^[\W_]*([^\d\W]+|$)//; $1 } ($a, $b);
            $_ = $sa cmp $sb and return $_;
        } else {
            return undef;
        }
    }
    return length($a) cmp length($b) || $a cmp $b;
}

Возвращает число в случае нормального сравнения и undef в случае, когда
численная порция приходится против буквенной (напр. 5mdk и ipl5mdk).

-- 
Stay tuned,
  MhZ                                    mailto:mookid@sigent.ru
-----------
It's reassuring to know that if you behave strangely enough, society will
take full responsibility for you.
_______________________________________________
Devel mailing list
Devel@linux.iplabs.ru
http://www.logic.ru/mailman/listinfo/devel


  reply	other threads:[~2000-12-19 23:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-19 21:40 Aleksey Novodvorsky
2000-12-19 23:35 ` Mikhail Zabaluev [this message]
2000-12-20  4:54   ` Aleksey Novodvorsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20001220023512.B1252@localhost.localdomain \
    --to=mookid@sigent.ru \
    --cc=devel@linux.iplabs.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git