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

possible "qw" bug #1108

Closed
p5pRT opened this issue Feb 1, 2000 · 16 comments
Closed

possible "qw" bug #1108

p5pRT opened this issue Feb 1, 2000 · 16 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 1, 2000

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

Searchable as RT2063$

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From dan_liddell@mentorg.com

Possible bug​:

$a = ("one", "two", "three");
# $a = three, as we would expect; however,

$a = qw(one two three);
# $a = 3, hmm... unexpected, does qw REALLY return a list?

Thanks!
--

***********************************************
Mathematics is that subject in which we never
know what we're talking about, nor whether
what we are saying is true.

  - Bertrand Russell
***********************************************

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From dan_liddell@mentorg.com

#! /usr/bin/perl -w

$a = ("one", "two", "three");
print "$a\n";
# $a = three, as we would expect; however,

$a = qw(one two three);
print "$a\n";
# $a = 3, hmm... unexpected, does qw REALLY return a list?

--

***********************************************
Mathematics is that subject in which we never
know what we're talking about, nor whether
what we are saying is true.

  - Bertrand Russell
***********************************************

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

$a = qw(one two three);
print "$a\n";
# $a = 3, hmm... unexpected, does qw REALLY return a list?

qw() is just shorthand for split ' ', q();

--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve japhy@​pobox.com
http​://www.pobox.com/~japhy/ http​://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine http​://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http​://www.perlarchive.com/

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

#! /usr/bin/perl -w

$a = ("one", "two", "three");
print "$a\n";
# $a = three, as we would expect; however,

$a = qw(one two three);
print "$a\n";
# $a = 3, hmm... unexpected, does qw REALLY return a list?

% perl5.005_63 -le '$a = qw(one two three); print $a'
three

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

On Feb 1, Tom Christiansen said​:

% perl5.005_63 -le '$a = qw(one two three); print $a'
three

That change had better be documented.

From 5.005_02's perlop.pod​:

  qw/STRING/
  Returns a list of the words extracted out of STRING,
  using embedded whitespace as the word delimiters.
  It is exactly equivalent to

  split(' ', q/STRING/);

  This equivalency means that if used in scalar
  context, you'll get split's (unfortunate) scalar
  context behavior, complete with mysterious warnings.

--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve japhy@​pobox.com
http​://www.pobox.com/~japhy/ http​://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine http​://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http​://www.perlarchive.com/

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

% perl5.005_63 -le '$a = qw(one two three); print $a'
three

That change had better be documented.

From 5.005_02's perlop.pod​:

qw/STRING/
        Returns a list of the words extracted out of STRING\,
        using embedded whitespace as the word delimiters\.
        It is exactly equivalent to
            split\(' '\, q/STRING/\);
        This equivalency means that if used in scalar
        context\, you'll get split's \(unfortunate\) scalar
        context behavior\, complete with mysterious warnings\.

Patches to perl{op,delta}.pod are, of course, everwelcome.

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

On Feb 1, Tom Christiansen said​:

qw/STRING/
        It is exactly equivalent to
            split\(' '\, q/STRING/\);

Patches to perl{op,delta}.pod are, of course, everwelcome.

Patches to perl{op,delta}.pod will be, of course, written, when I'm told
the new exact equivelent of qw(), and/or the behavior of split() in scalar
context.

--
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve japhy@​pobox.com
http​://www.pobox.com/~japhy/ http​://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine http​://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http​://www.perlarchive.com/

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

On Feb 1, Tom Christiansen said​:

qw/STRING/
        It is exactly equivalent to
            split\(' '\, q/STRING/\);

Patches to perl{op,delta}.pod are, of course, everwelcome.

Patches to perl{op,delta}.pod will be, of course, written, when I'm told
the new exact equivelent of qw(), and/or the behavior of split() in scalar
  ^^^^^ Are we talking equal-velars or equal-values???
context.

From perldelta.pod​:

  =head2 Improved C<qw//> operator

  The C<qw//> operator is now evaluated at compile time into a
  true list instead of being replaced with a run time call to
  C<split()>. This removes the confusing misbehaviour of C<qw//>
  in scalar context, which had inherited that behaviour from
  split().

  Thus​:

  $foo = ($bar) = qw(a b c); print "$foo|$bar\n";

  now correctly prints "3|a", instead of "2|a".

And from perlop.pod​:

  =item qw/STRING/

  Evaluates to a list of the words extracted out of STRING, using
  embedded whitespace as the word delimiters. It can be understood
  as being roughly equivalent to​:

  split(' ', q/STRING/);

  the difference being that it generates a real list at compile
  time. So this expression​:

  qw(foo bar baz)

  is semantically equivalent to the list​:

  'foo', 'bar', 'baz'

In summary, I believe that one would find that Sarathy has already
done the necessary docwork, were one but to read it. :-(

--tom

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From @TimToady

Dan Liddell writes​:
: # $a = 3, hmm... unexpected, does qw REALLY return a list?

Nothing ever returns a list in scalar context, so there's no reason to
expect qw() to do any particular thing. I'd say changing it to return
the last value is probably a bit of a flub. A good argument could be
made that it should return join(' ', qw(one two three)). At least then
it would have the useful function of turning arbitrary whitespace into
consistent whitespace.

Or maybe it should be join($", qw(one two three)).

Larry

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From @TimToady

Larry Wall writes​:
: Dan Liddell writes​:
: : # $a = 3, hmm... unexpected, does qw REALLY return a list?
:
: Nothing ever returns a list in scalar context, so there's no reason to
: expect qw() to do any particular thing. I'd say changing it to return
: the last value is probably a bit of a flub. A good argument could be
: made that it should return join(' ', qw(one two three)). At least then
: it would have the useful function of turning arbitrary whitespace into
: consistent whitespace.
:
: Or maybe it should be join($", qw(one two three)).

Before you guys leap to the (probably justifiable) conclusion that I'm
totally off my rocker, I should point out that there's precedent in qx//.

Actually, I'm just waiting for Unicode to take over so we can switch
to using those cute French angle quotes for qw(), which I've always thought
was rather ugly. Then we'll be debating the meaning of​:

  $a = «one two three»;

Larry

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

Larry Wall <larry@​wall.org> writes​:

Or maybe it should be join($", qw(one two three)).

For what it's worth, I like this idea, and can even see some use for it.

--
Russ Allbery (rra@​stanford.edu) <URL​:http​://www.eyrie.org/~eagle/>

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From [Unknown Contact. See original ticket]

From my own perspective there is a certain appeal to having qw(a b c) be
equivalent to ("a", "b", "c") up to isomorphism, but then again, what do
I know? The statement at the end of this message applies equally well to
perl.

Larry Wall wrote​:

Larry Wall writes​:
: Dan Liddell writes​:
: : # $a = 3, hmm... unexpected, does qw REALLY return a list?
:
: Nothing ever returns a list in scalar context, so there's no reason to
: expect qw() to do any particular thing. I'd say changing it to return
: the last value is probably a bit of a flub. A good argument could be
: made that it should return join(' ', qw(one two three)). At least then
: it would have the useful function of turning arbitrary whitespace into
: consistent whitespace.
:
: Or maybe it should be join($", qw(one two three)).

Before you guys leap to the (probably justifiable) conclusion that I'm
totally off my rocker, I should point out that there's precedent in qx//.

Actually, I'm just waiting for Unicode to take over so we can switch
to using those cute French angle quotes for qw(), which I've always thought
was rather ugly. Then we'll be debating the meaning of​:

$a = «one two three»;

Larry

--

***********************************************
Mathematics is that subject in which we never
know what we're talking about, nor whether
what we are saying is true.

  - Bertrand Russell
***********************************************

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2000

From @TimToady

Dan Liddell writes​:
: From my own perspective there is a certain appeal to having qw(a b c) be
: equivalent to ("a", "b", "c") up to isomorphism, but then again, what do I
: know. The statement at the end of this message applies equally well to perl.

Oh, I dunno. Perl is as much about religion as it is about mathematics,
and Bertrand Russell didn't seem to have any qualms about making any number
of absolute pronouncements about religion. So go for it. :-)

Larry

: ***********************************************
: Mathematics is that subject in which we never
: know what we're talking about, nor whether
: what we are saying is true.
:
: - Bertrand Russell
: ***********************************************

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2000

From [Unknown Contact. See original ticket]

Larry Wall wrote​:

Larry Wall writes​:
: Dan Liddell writes​:
: : # $a = 3, hmm... unexpected, does qw REALLY return a list?
:
: Nothing ever returns a list in scalar context, so there's no reason to
: expect qw() to do any particular thing. I'd say changing it to return
: the last value is probably a bit of a flub. A good argument could be
: made that it should return join(' ', qw(one two three)). At least then
: it would have the useful function of turning arbitrary whitespace into
: consistent whitespace.
:
: Or maybe it should be join($", qw(one two three)).

Before you guys leap to the (probably justifiable) conclusion that I'm
totally off my rocker, I should point out that there's precedent in qx//.

How about

Warning​: I don't think that means what you think it means.

Also, maybe the
$x = () = <insert list returning expr with odd !wantarray behavior here>
trick should be smeared around the documentation?

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2003

From @iabyn

Just reviewing old bugs from the Perl bug database​:

Possible bug​:

$a = ("one", "two", "three");
# $a = three, as we would expect; however,

$a = qw(one two three);
# $a = 3, hmm... unexpected, does qw REALLY return a list?

This has been fixed in more recent releases of Perl, such 5.6.1

@p5pRT
Copy link
Author

p5pRT commented Apr 30, 2003

@iabyn - Status changed from 'stalled' to 'resolved'

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