http://www.perlmonks.org?node_id=295636

ambrus has asked for the wisdom of the Perl Monks concerning the following question:

According to perl-5.8.1/pod/perldelta.pod the v-strings might be deprecated in later versions of perl. I do not understand why. I use v-strings on command line because v10 is much easier to input on keyboard then "\n". Pascal has a similar feature, the Pascal folks can write "hello world".v10 like this: 'hello world'#10

Replies are listed 'Best First'.
Re: Why will v-strings be deprecated
by Abigail-II (Bishop) on Oct 01, 2003 at 14:35 UTC
    But 'v10' also looks like a bareword. Consider this:
    sub u11 {"u11"} sub v11 {"v11"} sub w11 {"w11"} print u11, v11, w11, v10; __END__ u11v11w11

    And that includes the new line.

    There are more things that cause more confusion than they solve peoples problems:

    print 65.66; # prints '65.66' print 65.66.67; # prints 'ABC'
    And while you can use print v10 to print a newline, you can't use it to print two newlines (as opposed to one string with two newlines):
    print v10; # prints newline. print v10, v10; # "No comma allowed after filehandle"

    Abigail

      You're right. I think 10v would've been a better syntax instead of v10. Letters after numbers could be used for some interesting purposes: for example 3a could be short for $_[3].

      And while you can use print v10 to print a newline, you can't use it to print two newlines (as opposed to one string with two newlines):
      print v10; # prints newline. print v10, v10; # "No comma allowed after filehandle"

      For this purpose the following works:

      print v10 x 2; # prints 2 newlines
      Or even:
      print v10 x 1, v10; # also prints 2 newlines

Re: Why will v-strings be deprecated
by broquaint (Abbot) on Oct 01, 2003 at 14:28 UTC
      I think that this quote from that P5P message applies perfectly to the OP's usage:
      Further, people keep finding edge cases with v-strings and using them wrong.
      v-strings are not intended to compose Ascii characters with.

      To save time, you can jump right to the summary and then hit "Thread Next" to get the nail in the coffin (where the creator of v-strings admits that they must go).

                      - tye
Re: Why will v-strings be deprecated
by hardburn (Abbot) on Oct 01, 2003 at 14:21 UTC

    Maybe it's easier to type, but "\n" is a lot more readable. I don't want to have to look up an ASCII table just to understand your code.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: Why will v-strings be deprecated
by shenme (Priest) on Oct 01, 2003 at 14:44 UTC
    I've picked up on other people using $/ to avoid quoting difficulties.   It can be a problem getting the quoting right on Win command lines.   Using
        perl -e "print 'Hello World!',$/"
    
    works nicely.

      Even easier:)

      perl -le "print 'Hello World!'"

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        Easiest (assuming you have more than one output statement in your script):

        # THIS use feature 'say'; # OR use 5.10.0; # THEN say 'Hello, World!';

        Perl6::Say fails Build test, at least for me.

        Note: Contents may change.
      This is a good trick, I wouldn't have tought of it. I knew about perl -le.