OK I added this and I keep getting invalid format
foreach (@newValues){print "$_\n";}
my @versions;
while (@newValues)
{
chomp;
die "invalid format" unless
my ($major, $minor, $build) = /(\d+)(?:-.+)?\.(\d+)-(\d+)/;
push @versions, [ $major, $minor, $build , $_];
}
foreach (@versions){print "$_\n";}
}
/tmp# ./trim.pl
14.20-33
14.20-34
14.18-29
14.18-33
14.18-34
14.18-35
14.18-37
14.20-27
14.20-28
14.20-29
14.20-30
14.20-31
14.20-32
14.16-30
14.16-31
invalid format at ./trim.pl line 41. (41 is the die line)
Tony Heal
Pace Systems Group, Inc.
800-624-5999
[EMAIL PROTECTED]
> -----Original Message-----
> From: Chas Owens [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 21, 2007 9:50 AM
> To: [EMAIL PROTECTED]
> Cc: [email protected]
> Subject: Re: regex help
>
> On 8/21/07, Tony Heal <[EMAIL PROTECTED]> wrote:
> > Here is a sample of the versions that I am using.
> snip
>
> Just to clarify, you have a version string with the following format:
>
> {major}{custom tag}.{minor}-{build}
>
> and you want the list sorted by major, then minor, then build.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my @versions;
> while (<DATA>) {
> chomp;
> die "invalid format" unless
> my ($major, $minor, $build) = /(\d+)(?:-.+)?\.(\d+)-(\d+)/;
> push @versions, [ $major, $minor, $build , $_];
> }
>
> print "$_->[-1]\n" for sort {
> $a->[0] <=> $b->[0] or
> $a->[1] <=> $b->[1] or
> $a->[2] <=> $b->[2]
> } @versions;
>
> __DATA__
> 16.1-17
> 16.1-22
> 16.1-23
> 16.1-39
> 16.3-1
> 16.3-6
> 16.3-7
> 16.3-8
> 16.3-15
> 16.5-1
> 16.5-2
> 16.5-10
> 16.5-13
> 15.3-12
> 15.2-108
> 14-special.1-2
> 14-special.1-8
> 14-special.1-15
> 14-special.2-40
> 14-special.2-41
> 14-special.3-4
> 14-special.3-7
> 14-special.3-12
> 15.2-110
> 15.2-111
> 15-special.1-52
> 15-special.1-53
> 15-special.1-54
> 16-special.4-9
> 16-special.4-10
> 16-special.5-1
> 16-special.5-2
> 16-special.6-6
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/