Fun with v-strings ( or version-0-rama )
David Weinrich
dweinr1 at home.com
Sun Nov 18 12:02:03 CST 2001
After the meeting this week, I decided to do a little reading up on vstrings.
They have now been promoted from 'slightly odd' to 'really really weird' in my
book. Here is a quick program that tests conversion to/from vstrings ( using
version strings from the CVS $Revision:$ tag ). It looks like line 33 is a
fairly consistent way to convert versions as strings to v-strings.
David Weinrich
-------------- next part --------------
#!/usr/bin/perl -w
# Test to see how strings/numbers are converted to vstrings:
#
# A number that has no '.' ( 1 ) remains a string...
# A number that has one '.' ( 1.1 ) remains a string...
# A number that has more than one '.' is converted to a v-string
@versions = ( 1, 1.1, 1.1.1, 11.0.1, 10.0.0, 11.0.2 );
# Prints out the two strings as their numeric ascii values ( 1 = 49, . = 46 )
# The rest were converted to vstrings and sort/print as expected
foreach $v ( sort @versions ) {
printf "Version: %vd\n", $v;
}
# Stolen in part from Simon Cozens in the p5p roundup for 8/27/2001
# with another part stolen from the last SDPM meeting
$vstring = join '', map chr, split (/[.]/, qw$Revision: 1.11.1$[1]);
printf "Hex: %vx\n", $vstring;
printf "Decimal: %vd\n", $vstring;
printf "Octal: %vo\n", $vstring;
printf "Binary: %vb\n", $vstring;
# Hrm, can we get the numbers out directly with an unpack?
@parts = unpack "U*", $vstring;
# Yup
print "@parts\n";
# A final shortcut, uses a fairly improbable ( but I guess still
# possible ) version to test whether the vstring is stored as
# UTF-8 ( looks like the answer is yes ).
$vstring2 = pack "U*", split /[.]/, qw$Revision: 2573.1111$[1];
printf "Decimal: %vd\n", $vstring2;
More information about the San-Diego-pm
mailing list