in reply to Precedence of qw

Your greeting implies the problem is related to use strict, but it isn't.

use warnings; @array = qw(X) x 2; print @array, "\n";

gives

Unquoted string "x" may clash with future reserved word at 541178.pl l +ine 2. Number found where operator expected at 541178.pl line 2, near "x 2" (Do you need to predeclare x?) syntax error at 541178.pl line 2, near "qw(X) x " Execution of 541178.pl aborted due to compilation errors.

I've noticed this bug before.

Replies are listed 'Best First'.
Re^2: Precedence of qw
by eff_i_g (Curate) on Apr 04, 2006 at 16:58 UTC
    Sorry about that; it wasn't my intent.

    I noticed something else that I posted. This:
    #!/usr/bin/perl -w use strict; my $scalar = qw(A B C); print $scalar, "\n";
    Gives:
    Use of implicit split to @_ is deprecated at ./test27.pl line 4.
    3

    And perldiag has:
    Use of implicit split to @_ is deprecated
    (D deprecated) It makes a lot of work for the compiler when you clobber a subroutine's argument list, so it's better if you assign the results of a split() explicitly to an array (or list).

    I'm not sure how these are related...

      Your version of perl probably implements
      qw(A B C)
      as
      split(' ', q(A B C))
      (although I suspect it performs said split at compile-time).

      Given the above, consider the following passage from split's documentation:

      In scalar context, returns the number of fields found and splits into the @_ array. Use of split in scalar context is deprecated, however, because it clobbers your subroutine arguments.

      If you want the count, use my $scalar = () = qw(A B C);.

      By the way, I said "your version of perl" because perl 5.6.1 gives

      Useless use of a constant in void context at 541192.pl line 4. Useless use of a constant in void context at 541192.pl line 4. C

        The split is performed at runtime for perl prior to 5.6..

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      What version of perl are you using? Mine doesn't say that at all.

        duff, version 5.005_03 built for sun4-solaris. We have other versions on other machines; I'll try those out.
      $ perl -w use strict; my $scalar = qw(A B C); Useless use of a constant in void context at - line 3. Useless use of a constant in void context at - line 3. print $scalar, "\n"; C
      $ perl -v This is perl, v5.8.7 built for cygwin-thread-multi-64int (with 1 registered patch, see perl -V for more detail)
      By the way, this has nothing to do with qw.
      $ perl -w my $scalar = (1, 2, 3); Useless use of a constant in void context at - line 1.