Tony Heal am Dienstag, 21. August 2007:
> > -----Original Message-----
> > From: Chas Owens [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, August 21, 2007 9:50 AM
> > To: [EMAIL PROTECTED]
> > Cc: beginners@perl.org
> > 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
[snip]
> > 16-special.4-10
> > 16-special.5-1
> > 16-special.5-2
> > 16-special.6-6

Hello Tony

Just include the original line in the die message to see what caused it (an 
empty line would for example). 
Based on that, you can then adapt the regex.

> OK I added this and I keep getting invalid format
>
> foreach (@newValues){print "$_\n";}
>       my @versions;
>       while (@newValues)
>       {
>               chomp;
>               die "invalid format" unless

                die "invalid format of '$_'" unless

>               my ($major, $minor, $build) = /(\d+)(?:-.+)?\.(\d+)-(\d+)/;
>               push @versions, [ $major, $minor, $build , $_];
>       }
>       foreach (@versions){print "$_\n";}
> }
>
> /tmp# ./trim.pl
> 14.20-33
[snip]
> 14.16-31
> invalid format at ./trim.pl line 41. (41 is the die line)


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to