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

Closed
p5pRT opened this issue Oct 22, 1999 · 1 comment
Closed

qw and x operator #763

p5pRT opened this issue Oct 22, 1999 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented Oct 22, 1999

Migrated from rt.perl.org#1687 (status was 'resolved')

Searchable as RT1687$

@p5pRT
Copy link
Author

p5pRT commented Oct 22, 1999

From marcel.grunauer@lovely.net

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@​metronet.com)​:

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@​delanet.com)​:

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​:
  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-object
  uname=''
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef useperlio=undef d_sfio=undef
  Compiler​:
  cc='cl.exe', optimize='-O2 -MD -DNDEBUG -TP -GX', gccversion=
  cppflags='-DWIN32'
  ccflags ='-O2 -MD -DNDEBUG -TP -GX -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT -DPERL_OBJECT'
  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,
libperl=perlcore.lib
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
-machine​:x86'

Locally applied patches​:
  ACTIVEPERL_LOCAL_PATCHES_ENTRY


@​INC for perl 5.00502​:
  C​:\root\perldev\lib
  C​:\usr\lib
  C​:\usr\site\lib
  .


Environment for perl 5.00502​:
  HOME=C​:\root
  LANG (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)

PATH=c​:\cygnus\CYGWIN1\H-I5861\bin;.;C​:\usr\bin;C​:\WINNT\system32;C​:\WINNT;C​:\rootbin;c​:\cygnus\CYGWIN1\H-I5861\bin;G​:\jdk1.2.2\bin;c​:\Program
Files\Winzip;C​:\DAYNA
  PERL5LIB=C​:\root\perldev\lib
  PERL_BADLANG (unset)
  SHELL=/bin/sh

--
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
Projects
None yet
Development

No branches or pull requests

1 participant