Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • $^V ge "\5\x08\0" throws a warning

    8 answers - 715 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    a somewhat recent bleadperl comparing to $^V throws a warning. I
    had some old code which used $^V because the documentation said to. It
    threw this warning. I'm not going to keep the old code but I don't
    think the warning should have happened either.
    josh@lik:~$ bin/perl/5.9.4/bin/perl5.9.4 -Mwarnings -e '$^V ge "\5\x08\0"'
    Useless use of string ge in void context at -e line 1.
    Version string ' contains invalid data; ignoring: ' at -e line 1.
    The current documentation in perlvar doesn't appear to have wavered on
    that it's still best to compare against $^V. I thought $] was best
    again.
    John?
    Regards,
    Josh
  • No.1 | | 1563 bytes | |

    Joshua ben Jore wrote:
    josh@lik:~$ bin/perl/5.9.4/bin/perl5.9.4 -Mwarnings -e '$^V ge "\5\x08\0"'
    Useless use of string ge in void context at -e line 1.
    Version string ' contains invalid data; ignoring: ' at -e line 1.

    $ LD_LIBRARY_PATH=. ./perl -Ilib -MDevel::Peek -we '$v = "\5\x08\0"; Dump($v)'
    SV = PV(0x8272040) at 0x8286320
    REFCNT = 1
    FLAGS = (PK,pPK)
    PV = 0x8281048 "\5\10\0"\0
    CUR = 3
    LEN = 4

    I'm kind of stuck here. There is no way for me to know that you have hand
    crafted what is equivalent to a v-string without using the magic v-string code
    (found in 5.8.1 or better):

    $ LD_LIBRARY_PATH=. ./perl -Ilib -MDevel::Peek -we '$v = 5.8.0; Dump($v)'
    SV = PVMG(0x82a02b8) at 0x8286320
    REFCNT = 1
    FLAGS = (RMG,PK,pPK)
    IV = 0
    NV = 0
    PV = 0x8281048 "\5\10\0"\0
    CUR = 3
    LEN = 4
    MAGIC = 0x82a21d8
    MG_VIRTUAL = 0
    MG_TYPE = PERL_MAGIC_vstring(V)
    MG_LEN = 5
    MG_PTR = 0x827ce40 "5.8.0"

    The only think I can think of doing is to throw in a heuristic like this
    (currently only in the pure Perl version.pm release):

    # may be a non-magic v-string
    if ( $] >= 5.006_002 && $] < 5.008_001
    && length($value) >= 3 && $value !~ /[._]/ ) {
    my $tvalue = sprintf("%vd",$value);
    if ( $tvalue =~ /^\d+\.\d+\.\d+$/ ) {
    # must be a non-magic v-string
    $value = $tvalue;
    }
    }

    but that isn't guaranteed to be correct, just highly unlikely to be wrong

    John
  • No.2 | | 1018 bytes | |

    6/21/06, John Peacock <jpeacock (AT) rowman (DOT) comwrote:
    Joshua ben Jore wrote:
    josh@lik:~$ bin/perl/5.9.4/bin/perl5.9.4 -Mwarnings -e '$^V ge "\5\x08\0"'
    Useless use of string ge in void context at -e line 1.
    Version string ' contains invalid data; ignoring: ' at -e line 1.

    I'm kind of stuck here. There is no way for me to know that you have hand
    crafted what is equivalent to a v-string without using the magic v-string code
    (found in 5.8.1 or better):

    You're stuck?! The docs say I'm supposed to make a string equivalent
    to C<chr(5) . chr(8) . chr(0)>! That's the "old" current docs starting
    at 5.6.0 and the stuff that's still in the "new" current docs still in
    my synched up bleadperl. I figured the documentation was promising
    that this would work and be more backwards compatible than using the
    v5.8.0 syntax.

    Major bummer. I know you did oodles of work on this earlier. :-(

    Josh
  • No.3 | | 1452 bytes | |

    22/06/06, Joshua ben Jore <twists (AT) gmail (DOT) comwrote:
    6/21/06, John Peacock <jpeacock (AT) rowman (DOT) comwrote:
    Joshua ben Jore wrote:
    josh@lik:~$ bin/perl/5.9.4/bin/perl5.9.4 -Mwarnings -e '$^V ge "\5\x08\0"'
    Useless use of string ge in void context at -e line 1.
    Version string ' contains invalid data; ignoring: ' at -e line 1.

    I'm kind of stuck here. There is no way for me to know that you have hand
    crafted what is equivalent to a v-string without using the magic v-string code
    (found in 5.8.1 or better):

    You're stuck?! The docs say I'm supposed to make a string equivalent
    to C<chr(5) . chr(8) . chr(0)>!

    But you still have that string. You only have a bit of V magic in it.
    If you use a version string the comparison works.

    the other hand, $^V is not a plain scalar, it's an object, and it
    doesn't stringify to a string of non printable chars.

    I'm not sure adding heuristics to scan_version would be a good idea,
    that might introduce inconsistencies and puzzle users.

    That's the "old" current docs starting
    at 5.6.0 and the stuff that's still in the "new" current docs still in
    my synched up bleadperl. I figured the documentation was promising
    that this would work and be more backwards compatible than using the
    v5.8.0 syntax.

    Which docs need an update?
  • No.4 | | 746 bytes | |

    6/22/06, Rafael Garcia-Suarez <rgarciasuarez (AT) gmail (DOT) comwrote:
    the other hand, $^V is not a plain scalar, it's an object, and it
    doesn't stringify to a string of non printable chars.

    The documentation in perlvar says that $^V stringifies to a string
    like C<chr(5) . chr(6) . chr(0)which is nonprintable. perlvar has
    said this since 5.6.0 and it still does. I didn't realize it but the
    current stringification of $^V in bleadperl is contrary to what's been
    documented. Per the docs, $^V eq "\005\011\004" is the correct
    response and the "v5.9.4" is the wrong response.

    Maybe we want a $^Version variable if we want something to stringify
    to "v5.9.4".

    Josh
  • No.5 | | 1720 bytes | |

    Joshua ben Jore wrote:
    The documentation in perlvar says that $^V stringifies to a string
    like C<chr(5) . chr(6) . chr(0)which is nonprintable. perlvar has
    said this since 5.6.0 and it still does. I didn't realize it but the
    current stringification of $^V in bleadperl is contrary to what's been
    documented. Per the docs, $^V eq "\005\011\004" is the correct
    response and the "v5.9.4" is the wrong response.

    You're right, I should have updated the documentation when I added the
    $^V object patch. I made sure that the more common case (of trying to
    print out $^V) still worked, even though $^V is now an object:

    $ LD_LIBRARY_PATH=. ./perl -e 'printf("%vd",$^V)'
    5.9.4

    But, to actually quote the documentation:

    >$^V The revision, version, and subversion of the Perl interpreter,

    represented as a string composed of characters with those ordi-
    nals. Thus in Perl v5.6.0 it equals "chr(5) . chr(6) . chr(0)"
    and will return true for "$^V eq v5.6.0". Note that the char-
    acters in this string value can potentially be in Unicode
    range.

    This can be used to determine whether the Perl interpreter exe-
    cuting a script is in the right range of versions. (Mnemonic:
    use ^V for Version Control.) Example:

    warn "No \"our\" declarations!\n" if $^V and $^V lt v5.6.0;

    Which is all strictly true: in Perl v5.6.0, $^V is the same as "chr(5) .
    chr(6) . chr(0)"; it just isn't true in 5.9.x. It is only because you
    used the form "\5\x08\0" that anything broke. Had you used the examples
    cited (using v-strings), you would never have noticed anything wrong

    John
  • No.6 | | 1025 bytes | |

    6/22/06, John Peacock <jpeacock (AT) rowman (DOT) comwrote:
    Which is all strictly true: in Perl v5.6.0, $^V is the same as "chr(5) .
    chr(6) . chr(0)"; it just isn't true in 5.9.x. It is only because you
    used the form "\5\x08\0" that anything broke. Had you used the examples
    cited (using v-strings), you would never have noticed anything wrong

    I think the documentation used chr(5).chr(6).chr(0) as an example, not
    a statement that the behavior was true only in 5.6.0. It certainly
    reads that way. I wouldn't have thought that the docs were defining
    $^V for the 5.6.0 perl and that the format was undefined for all other
    versions. I think this is really splitting hairs if you mean that when
    it says the string is chr(5).chr(6).chr(0) it really means that the
    only valid way to make that value is v5.6.0.

    I'm pretty sure that it's wrong for $^V to stringify the way you've
    got it going now. Pleasant as the stringification is.

    Josh
  • No.7 | | 1231 bytes | |

    Joshua ben Jore wrote:
    I think the documentation used chr(5).chr(6).chr(0) as an example, not
    a statement that the behavior was true only in 5.6.0. It certainly
    reads that way. I wouldn't have thought that the docs were defining
    $^V for the 5.6.0 perl and that the format was undefined for all other
    versions. I think this is really splitting hairs if you mean that when
    it says the string is chr(5).chr(6).chr(0) it really means that the
    only valid way to make that value is v5.6.0.

    I /am/ splitting hairs, since I said it was "strictly" true. But you are
    still ignoring my point that the actual example of using $^V for
    comparison purposes _in_ _the_ _PD_ uses v-strings, which continues to
    work with version objects. Believe me, if I had know where the
    v-string/version object stuff would have gone, and the totally off the
    wall way people have used v-strings in the past, I wouldn't have done
    *any* of this work. I've seen things that ordinary humans just weren't
    meant to see! ;-)

    I think the documentation needs to be altered to eliminate any
    discussion of the underlying representation and merely discuss the
    correct usage of $^V.

    John
  • No.8 | | 899 bytes | |

    6/22/06, John Peacock <jpeacock (AT) rowman (DOT) comwrote:
    I /am/ splitting hairs, since I said it was "strictly" true. But you are
    still ignoring my point that the actual example of using $^V for
    comparison purposes _in_ _the_ _PD_ uses v-strings, which continues to
    work with version objects. Believe me, if I had know where the

    I saw that the docs did say C<$^V ge v5.8.0(or some other version)
    but they did also promise a particular kind of stringification. I
    didn't think I needed to mention that the docs show a comparision
    using a real v-string. I figured that given the documentation's
    promise of a particular kind of stringification that I could just
    state that and that would be the end of it. I don't think we have a
    perly notion that you can make a string that can't be compared to
    other strings.

    Josh

Re: $^V ge "\5\x08\0" throws a warning


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Perl"

EMSDN.COM