From: "Dr.Ruud" <[EMAIL PROTECTED]>
> Matthew Whipple schreef:
> > Dr.Ruud:
> >> Tatiana Lloret Iglesias:
>
> >>> What regular expression do I need to convert Version: 1.2.3 to
> >>> Version:
> >>> 1.2.4 ?
> >>>
> >>> I.e. my pattern is Version: number.number.number and from that i
> >>> need Version: number.number.number+1
> >>> After the : i can have a space or not...
> >>>
> >>
> >> Why use a regex?
> >>
> >> perl -wle '
> >> $v = 2.1.1;
> >> printf "%vd\n", $v;
> >> substr $v, -1, 1, chr ord(substr $v, -1, 1) + 1;
> >> printf "%vd\n", $v
> >> '
> >>
> >> See also version.pm
> >
> > This wouldn't scale past double digits.
>
> Why not?
>
> $ perl -wle '
> $v = 1.23456.777888999;
> printf "%vd\n", $v;
> substr $v, -1, 1, chr ord(substr $v, -1, 1) + 1;
> substr $v, -2, 1, chr ord(substr $v, -2, 1) + 1;
> printf "%vd\n", $v
> '
> 1.23456.777888999
> 1.23457.777889000
Well this is a bit tricky. The OP doesn't have a
$version = 1.2.3
, he has a string
$v = 'Version: 1.2.3'
Try
print( (1.2.3 eq '1.2.3') ? 'yes' : 'no');
Try your code on
$v = 'Version: 1.23456.777888999';
Not so good anymore, right? And if you print the $v directly you get
Version: 1.23456.7778889::
not good either.
You are using "Version Strings". From perldoc perldata:
Note: Version Strings (v-strings) have been deprecated. They will not
be available after Perl 5.8. The marginal benefits of v-strings were
greatly outweighed by the potential for Surprise and Confusion.
A literal of the form v1.20.300.4000 is parsed as a string composed
of characters with the specified ordinals. This form, known as v-
strings, provides an alternative, more readable way to construct
strings, rather than use the somewhat less readable interpolation
form "\x{1}\x{14}\x{12c}\x{fa0}". This is useful for representing
Unicode strings, and for comparing version "numbers" using the string
comparison operators, cmp, gt, lt etc. If there are two or more dots
in the literal, the leading v may be omitted.
print v9786; # prints UTF-8 encoded SMILEY,
"\x{263a}"
print v102.111.111; # prints "foo"
print 102.111.111; # same
Such literals are accepted by both require and use for doing a
version check. The $^V special variable also contains the running
Perl interpreter's version in this form. See "$^V" in perlvar. Note
that using the v-strings for IPv4 addresses is not portable unless
you also use the inet_aton()/inet_ntoa() routines of the Socket
package.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/