Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Surprising Syntax

by Chmrr (Vicar)
on Aug 06, 2002 at 05:17 UTC ( #187929=note: print w/replies, xml ) Need Help??

in reply to Surprising Syntax

Yup. See box below for an explanation. Interestingly enough, I do get the same abnormal behavior with 5.6.0, unlike belg4mit.

v-strings are rather kludges in my opinion, and it comes up here. The v1 is being interpreted as a v-string; Data::Dumper shows what's going on:

$VAR1 = { 'u1' => 1, 'u' => 1, '' => 1, 'v' => 1, 't1' => 1, 't' => 1 };

Naughty v-strings!

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Replies are listed 'Best First'.
Re: Surprising Syntax
by crenz (Priest) on Aug 06, 2002 at 05:28 UTC

    Yes, it took me quite a while, a hex editor (for the output) and some documentation to see what's going on :-).

    I tend towards seeing this as a bug. => is supposed to "force any word to the left of it to be interpreted as a string" (perlop). Also, it violates the principle of least surprise. I noticed that e.g. 0xC0 => "value" will be interpolated as well, though.

Re: Re: Surprising Syntax
by graff (Chancellor) on Aug 06, 2002 at 05:42 UTC
    Umm... so, I'm guessing that "v-string" means "vector string" -- am I wrong? And I'm wondering which Perl man page describes it. (I looked at perldoc -f vec and perldoc perlop, but didn't see it.)

      Close -- it stands for both "vector" and/or "version" string. See Everything you wanted to know about Module Version Numbers and Checking for more while I hunt down something from the perl distribution which discussed them.

      Update: Can't find anything about it in the core perl documentation, but there's a small bit about them in Programming Perl, version 3. A short exerpt from section 2.6.7 from my version on Safari:

      A literal that begins with a v and is followed by one or more dot-separated integers is treated as a string literal composed of characters with the specified ordinal values:

      $crlf = v13.10;           # ASCII carriage return, line feed

      These are called v-strings, short for "vector strings" or "version strings" or anything else you can think of that starts with "v" and deals with lists of integers. They provide an alternate and more legible way to construct strings when you want to specify the numeric values of each character. Thus, v1.20.300.4000 is a more winsome way to produce the same string value as any of:

      "\x{1}\x{14}\x{12c}\x{fa0}" pack("U*", 1, 20, 300, 4000) chr(1) . chr(20) . chr(300) . chr(4000)

      perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

        $crlf = v13.10;

        Unfortunately, that is not true on ActiveState perl 5.6.1.

        v10 produces the bytes 0x0D 0x0A, so that v13.10 results in 0x0D 0x0D 0x0A. I guess this has to do with STDOUT being considered an "ascii" file on Windows.

      I found it on perldelta in perl 5.6.1

      Support for strings represented as a vector of ordinals

      Literals of the form v1.2.3.4 are now parsed as a string composed of characters with the specified ordinals. This is an alternative, more readable way to construct (possibly Unicode) strings instead of interpolating characters, as in "\x{1}\x{2}\x{3}\x{4}". The leading v may be omitted if there are more than two ordinals, so 1.2.3 is parsed the same as v1.2.3.

      Strings written in this form are also useful to represent version "numbers". It is easy to compare such version "numbers" (which are really just plain strings) using any of the usual string comparison operators eq, ne, lt, gt, etc., or perform bitwise string operations on them using |, &, etc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://187929]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-03-18 17:36 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (230 votes). Check out past polls.