Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qw and x operator #763

p5pRT opened this issue Oct 22, 1999 · 1 comment

qw and x operator #763

p5pRT opened this issue Oct 22, 1999 · 1 comment


Copy link

p5pRT commented Oct 22, 1999

Migrated from (status was 'resolved')

Searchable as RT1687$

Copy link

p5pRT commented Oct 22, 1999


I've come across a behavior of the qw() operator in conjunction with
the x operator that I can't explain. I've checked perlop.

#!/usr/bin/perl -w
use strict;
my %test;
@​test{qw/a b c/} = ('n') x 3;
print "$_ => $test{$_}\n" foreach keys %test;

produces, as expected​:

a => n
b => n
c => n

If I replace the hash slice line above with

@​test{qw/a b c/} = qw/n/ x 3;

it produces​:

Bareword "x" not allowed while "strict subs" in use at ...
Unquoted string "x" may clash with future reserved word at ...
syntax error at ..., near "qw/n/ x "
Number found where operator expected at ..., near "x 3"
  (Do you need to predeclare x?)

The following two work ok​:

@​test{qw/a b c/} = (qw/n/) x 3;
@​test{qw/a b c/} = (split(' ', q/n/)) x 3;

According to Tad McClellan (tadmc@​​:

Note also that you get the same messages if you replace the
line above with just​:

x 3;

Looks like perl is taking "@​test{qw/a b c/} = qw/n/" as an
entire statement, and then resuming the parse...

According to Abigail (abigail@​​:

Based on [the repetition operator documentation], I would assume that

@​test\{qw/a b c/\} = qw/n/ x 3;

would lead to​:

%test = \(a => '111'\, b => undef\, c => undef\);

This is because the left operand of x will be evaluated in scalar context,
hence the split qw// does is done to @​_, and the amount of produced fields
is returned. This being 1, leads to 1 x 3 which is '111'.

Site configuration information for perl 5.00502​:

Summary of my perl5 (5.0 patchlevel 5 subversion 02) configuration​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-object
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef useperlio=undef d_sfio=undef
  cc='cl.exe', optimize='-O2 -MD -DNDEBUG -TP -GX', gccversion=
  stdchar='char', d_stdstdio=define, usevfork=false
  intsize=4, longsize=4, ptrsize=4, doublesize=8
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -release -machine​:x86'
  libpth="C​:\usr\lib\core" "C​:\Program Files\Mts\Lib"
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib PerlCRT.lib
  libc=C​:\usr\lib\core\PerlCRT.lib, so=dll, useshrplib=yes,
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release

Locally applied patches​:

@​INC for perl 5.00502​:

Environment for perl 5.00502​:
  LANG (unset)
  LOGDIR (unset)

  PERL_BADLANG (unset)

Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*​::;;;y;_; ;;print}&Just_Another_Perl_Hacker;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant