Closed p5pRT closed 18 years ago
for instance
$ perl -e 'print qw|foo bar| x 3' Number found where operator expected at -e line 1\, near "x 3" (Do you need to predeclare x?) syntax error at -e line 1\, near "qw|foo bar| x " Execution of -e aborted due to compilation errors.
while
$ perl -e '$\,="-"; print ((qw|foo bar|) x 3)' foo-bar-foo-bar-foo-bar
produces the desired behaviour
Cheers
- Salvador.
for instance:
$ perl -e '@foo = qw(foo bar) x 3' Number found where operator expected at -e line 1\, near "x 3" (Do you need to predeclare x?) syntax error at -e line 1\, near "qw(foo bar) x " Execution of -e aborted due to compilation errors.
I would expect 'qw(foo bar) x 3' to behave as '(qw(foo bar)) x 3'
Cheers\,
- Salvador.
On Thu\, May 19\, 2005 at 04:12:45PM -0000\, Salvador FandiÃÂño wrote:
for instance:
$ perl -e '@foo = qw(foo bar) x 3' Number found where operator expected at -e line 1\, near "x 3" (Do you need to predeclare x?) syntax error at -e line 1\, near "qw(foo bar) x " Execution of -e aborted due to compilation errors.
I would expect 'qw(foo bar) x 3' to behave as '(qw(foo bar)) x 3'
perlop says:
In list context\, if the left operand is enclosed in parentheses\, it repeats the list.
I would rather not add qw to that as an additional special case; instead qw(foo bar) x 3 should behave as scalar(qw(foo bar)) x 3\, generating a single string "barbarbar" (and a warning "Useless use of a constant in void context").
To get qw/foo bar foo bar foo bar/\, just enclose the qw// in parentheses: (qw/foo bar/ x 3).
The RT System itself - Status changed from 'new' to 'open'
--- Yitzchak Scott-Thoennes via RT \perlbug\-followup@​perl\.org wrote:
To get qw/foo bar foo bar foo bar/\, just enclose the qw// in parentheses: (qw/foo bar/ x 3).
that doesn't work either\, did you meant...
(qw/foo bar/) x 3
?
cheers\,
- Salvador
__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail
On Thu\, May 19\, 2005 at 11:13:44PM -0700\, Salvador Fandiño wrote:
--- Yitzchak Scott-Thoennes wrote:
To get qw/foo bar foo bar foo bar/\, just enclose the qw// in parentheses: (qw/foo bar/ x 3).
that doesn't work either\, did you meant...
(qw/foo bar/) x 3
Oops. Yes.
Yitzchak Scott-Thoennes wrote:
On Thu\, May 19\, 2005 at 04:12:45PM -0000\, Salvador Fandiño wrote:
for instance:
$ perl -e '@foo = qw(foo bar) x 3' Number found where operator expected at -e line 1\, near "x 3" (Do you need to predeclare x?) syntax error at -e line 1\, near "qw(foo bar) x " Execution of -e aborted due to compilation errors.
I would expect 'qw(foo bar) x 3' to behave as '(qw(foo bar)) x 3'
perlop says:
In list context\, if the left operand is enclosed in parentheses\, it repeats the list.
I would rather not add qw to that as an additional special case; instead qw(foo bar) x 3 should behave as scalar(qw(foo bar)) x 3\, generating a single string "barbarbar" (and a warning "Useless use of a constant in void context").
There's indeed a bug\, since the tokenizer doesn't set its state after parsing qw/..../. Fixed by this nit :
--- toke.c (revision 4822) +++ toke.c (working copy) @@ -4956\,6 +4956\,7 @@ s = scan_str(s\,FALSE\,FALSE); if (!s) missingterm((char*)0); + PL_expect = XOPERATOR; force_next(')'); if (SvCUR(PL_lex_stuff)) { OP *words = Nullop; End
But... technically I agree with Yitzchak on the exegesis of perlop\, qw() has a strong "list" feeling. Moreover\, perl 6 seems to agree :
$ ./pugs -e 'say for qw(foo bar) xx 2' foo bar foo bar
(asking on #perl6 confirms this.) And Perl 5 hasn't a strong history of not introducing special parsing cases. So I'll think I'll made it work like this :
$ bleadperl -le 'print for qw(foo bar) x 2' foo bar foo bar
On Fri\, May 20\, 2005 at 11:07:25AM +0200\, Rafael Garcia-Suarez wrote:
Yitzchak Scott-Thoennes wrote:
On Thu\, May 19\, 2005 at 04:12:45PM -0000\, Salvador Fandi??o wrote:
for instance:
$ perl -e '@foo = qw(foo bar) x 3' Number found where operator expected at -e line 1\, near "x 3" (Do you need to predeclare x?) syntax error at -e line 1\, near "qw(foo bar) x " Execution of -e aborted due to compilation errors.
I would expect 'qw(foo bar) x 3' to behave as '(qw(foo bar)) x 3'
perlop says:
In list context\, if the left operand is enclosed in parentheses\, it repeats the list.
I would rather not add qw to that as an additional special case; instead qw(foo bar) x 3 should behave as scalar(qw(foo bar)) x 3\, generating a single string "barbarbar" (and a warning "Useless use of a constant in void context").
There's indeed a bug\, since the tokenizer doesn't set its state after parsing qw/..../. Fixed by this nit :
--- toke.c (revision 4822) +++ toke.c (working copy) @@ -4956\,6 +4956\,7 @@ s = scan_str(s\,FALSE\,FALSE); if (!s) missingterm((char*)0); + PL_expect = XOPERATOR; force_next(')'); if (SvCUR(PL_lex_stuff)) { OP *words = Nullop; End
But... technically I agree with Yitzchak on the exegesis of perlop\, qw() has a strong "list" feeling. Moreover\, perl 6 seems to agree :
$ ./pugs -e 'say for qw(foo bar) xx 2' foo bar foo bar
(asking on #perl6 confirms this.) And Perl 5 hasn't a strong history of not introducing special parsing cases. So I'll think I'll made it work like this :
$ bleadperl -le 'print for qw(foo bar) x 2' foo bar foo bar
That's the opposite of what I was trying to say. I think of ()x and x as being two separate operators\, that happen to behave the same in scalar context. I don't think the list form should apply if there aren't explict parens around the left operand.
Yitzchak Scott-Thoennes wrote:
$ bleadperl -le 'print for qw(foo bar) x 2' foo bar foo bar
That's the opposite of what I was trying to say.
Yes\, I'm quite aware of this :) A "nonetheless" is missing in my previous mail.
I think of ()x and x as being two separate operators\, that happen to behave the same in scalar context. I don't think the list form should apply if there aren't explict parens around the left operand.
Yes... but from a DWIM point of view I think that people are used to assume () around qw lists; or to see qw just as another form of lists. And (qw(foo bar)) is just clutter\, since qw(foo bar) x 3 is not going to be used usefully.
Perl 6 works around this difficulty by having separate x and xx operators.
On Fri\, May 20\, 2005 at 11:07:25AM +0200\, Rafael Garcia-Suarez wrote:
qw() has a strong "list" feeling. Moreover\, perl 6 seems to agree :
$ ./pugs -e 'say for qw(foo bar) xx 2' foo bar foo bar
Is p6's xx supposed to have both roles of p5's x?
It sure seems to work differently; I'm told that this:
./pugs -e 'sub foo { ("foo"\,"bar") } say for foo() xx 2'
produces foo bar foo bar
also\, while for perl5\, we have:
$ ./perl -le'sub foo { ("foo"\,"bar") } print for foo() x 2' barbar
On 5/20/05\, Rafael Garcia-Suarez \rgarciasuarez@​mandriva\.com wrote:
Yitzchak Scott-Thoennes wrote:
$ bleadperl -le 'print for qw(foo bar) x 2' foo bar foo bar
That's the opposite of what I was trying to say.
Yes\, I'm quite aware of this :) A "nonetheless" is missing in my previous mail.
I think of ()x and x as being two separate operators\, that happen to behave the same in scalar context. I don't think the list form should apply if there aren't explict parens around the left operand.
Yes... but from a DWIM point of view I think that people are used to assume () around qw lists; or to see qw just as another form of lists. And (qw(foo bar)) is just clutter\, since qw(foo bar) x 3 is not going to be used usefully.
theres precedence for this interpretation as well:
D:\dev>perl -wle "use strict; for my $x qw(foo bar baz) { print $x }" foo bar baz
-- perl -Mre=debug -e "/just|another|perl|hacker/"
Yitzchak Scott-Thoennes wrote:
On Fri\, May 20\, 2005 at 11:07:25AM +0200\, Rafael Garcia-Suarez wrote:
qw() has a strong "list" feeling. Moreover\, perl 6 seems to agree :
$ ./pugs -e 'say for qw(foo bar) xx 2' foo bar foo bar
Is p6's xx supposed to have both roles of p5's x?
No; as Synopsis 03 says :
x splits into two operators: x (which concatenates repetitions of a string to produce a single string)\, and xx (which creates a list of repetitions of a list or scalar).
It sure seems to work differently; I'm told that this:
./pugs -e 'sub foo { ("foo"\,"bar") } say for foo() xx 2'
produces foo bar foo bar
also\, while for perl5\, we have:
$ ./perl -le'sub foo { ("foo"\,"bar") } print for foo() x 2' barbar
I don't see the point... My point was that qw() forces immediate list context on x; not that it forces list context on function return. (i.e. that qw(foo bar) is more like ("foo"\,"bar") than like "foo"\,"bar".)
Rafael Garcia-Suarez wrote:
There's indeed a bug\, since the tokenizer doesn't set its state after parsing qw/..../. Fixed by this nit :
--- toke.c (revision 4822) +++ toke.c (working copy) @@ -4956\,6 +4956\,7 @@ s = scan_str(s\,FALSE\,FALSE); if (!s) missingterm((char*)0); + PL_expect = XOPERATOR; force_next(')'); if (SvCUR(PL_lex_stuff)) { OP *words = Nullop; End
I applied this as change 24560 to bleadperl\, with a regression test that says :
is( (join '\,'\, (qw(a b c) x 3))\, 'a\,b\,c\,a\,b\,c\,a\,b\,c'\, 'x on qw produces list' );
-- The universe (which others call the Library) is composed of an indefinite and perhaps infinite number of hexagonal galleries. -- Borges
@rgs - Status changed from 'open' to 'resolved'
On Tue\, May 24\, 2005 at 01:51:52PM +0200\, Rafael Garcia-Suarez wrote:
Rafael Garcia-Suarez wrote:
There's indeed a bug\, since the tokenizer doesn't set its state after parsing qw/..../. Fixed by this nit :
--- toke.c (revision 4822) +++ toke.c (working copy) @@ -4956\,6 +4956\,7 @@ s = scan_str(s\,FALSE\,FALSE); if (!s) missingterm((char*)0); + PL_expect = XOPERATOR; force_next(')'); if (SvCUR(PL_lex_stuff)) { OP *words = Nullop; End
I applied this as change 24560 to bleadperl\, with a regression test that says :
is( (join '\,'\, (qw(a b c) x 3))\, 'a\,b\,c\,a\,b\,c\,a\,b\,c'\, 'x on qw produces list' );
Yitzchak Scott-Thoennes wrote:
I applied this as change 24560 to bleadperl\, with a regression test that says :
is( (join '\,'\, (qw(a b c) x 3))\, 'a\,b\,c\,a\,b\,c\,a\,b\,c'\, 'x on qw produces list' );
--- perl/pod/perlop.pod.orig 2005-05-10 08:07:42.000000000 -0700 +++ perl/pod/perlop.pod 2005-05-24 08:50:05.524456000 -0700 @@ -250\,9 +250\,9 @@ operand is not enclosed in parentheses\, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context\, if the left operand is enclosed in -parentheses\, it repeats the list. If the right operand is zero or -negative\, it returns an empty string or an empty list\, depending on the -context. +parentheses or is a list formed by C\<qw/STRING/>\, it repeats the list. +If the right operand is zero or negative\, it returns an empty string +or an empty list\, depending on the context.
Right; thanks\, applied as change #24567.
Migrated from rt.perl.org#35885 (status was 'resolved')
Searchable as RT35885$