Closed p5pRT closed 15 years ago
perl -wle 'sub foo { return 1..5} print sort foo(8)' 8
while a bit annoying (I wanted to sort the result of foo applied to 8)\, this is actually what is documented as the sort SUBNAME LIST form of sort. foo is the subname and there is one value to be sorted: 8
5.6.1 this will reportedly behaves the same (I don't have a 5.6.1 anymore)
More interesting: perl -wle 'sub foo { return 1..5} print sort(foo(8))' 12345
I see nothing in the sort docs that would make me expect a change in behaviour here by just adding parenthesis. (Nor does it in real indirect object cases like print(STDERR "foo"))
And on 5.6.1 it actually didn't matter: perl -wle 'sub foo { return 1..5} print sort(foo(8))' Unquoted string "foo" may clash with future reserved word at -e line 1. 8
So you get an extra warning and it behaves the same as without the parenthesis. For both things I think that the 5.6.1 behaviour was the right one. In fact\, I'd also have expected the unquoted string warning for the case without parenthesis\, but it seems 5.6.1 doesn't do that.
If you don't agree with me that these are bugs\, this behaviour should at least be documented.
[perl-5.8.0@ton.iguana.be - Sat Jun 19 11:06:22 2004]:
perl -wle 'sub foo { return 1..5} print sort foo(8)' 8
while a bit annoying (I wanted to sort the result of foo applied to 8)\, this is actually what is documented as the sort SUBNAME LIST form of sort. foo is the subname and there is one value to be sorted: 8
5.6.1 this will reportedly behaves the same (I don't have a 5.6.1 anymore)
5.6.2 does.
More interesting: perl -wle 'sub foo { return 1..5} print sort(foo(8))' 12345
I see nothing in the sort docs that would make me expect a change in behaviour here by just adding parenthesis. (Nor does it in real indirect object cases like print(STDERR "foo"))
I don't think print is the right analogy here. map and grep have the closest interface to sort.
So you get an extra warning and it behaves the same as without the parenthesis. For both things I think that the 5.6.1 behaviour was the right one. In fact\, I'd also have expected the unquoted string warning for the case without parenthesis\, but it seems 5.6.1 doesn't do that.
If you don't agree with me that these are bugs\, this behaviour should at least be documented.
I don't know if its a bug so much as an ambiguity made espcially tricky by its reliance on whitespace to DWIM. Changing the behavior to this would seem to be more like folks would expect.
sort foo(8) # call foo(8) and hand the results to sort sort foo (8) # use foo() as the sort routine to sort the list (8).
And before the C\<func (arg)> style camp objects\, its not working properly for that style now anyway.
The RT System itself - Status changed from 'new' to 'open'
I believe that "sort fn( EXPR\, EXPR )" is mistakenly being parsed as "sort fn ( EXPR\, EXPR )". The following code produces these results:
Unexpected: Key2 Key1 KeyB KeyD KeyC KeyA KeyB KeyC MoreLikeIt: Key1 Key2 KeyA KeyB KeyC KeyD
#--------------------- snip snip snip ------------------
#!/usr/bin/env perl5
use warnings;
use strict;
my %data = ( Key1 => { KeyA => 1\,
KeyB => 2\,
KeyC => 3 }\,
Key2 => { KeyB => 2\,
KeyC => 3\,
KeyD => 4 }\,
);
my @unexpected = sort uniq( keys( %data )\,
map{ keys %$_ } values %data );
my @moreLikeIt = sort( uniq( keys( %data )\,
map{ keys %$_ } values %data ));
print "Unexpected: @unexpected\nMoreLikeIt: @moreLikeIt\n";
sub uniq {
my %hash;
@hash{ @_ } = ();
return keys %hash;
}
#--------------------- snip snip snip ------------------
I believe that the "sort SUBNAME LIST" interpretation is incorrect because
1) 'perldoc perlop'\, in terms "Terms and List Operators (Leftward)" section says "function whose arguments are parenthesized" has the highest precedence in Perl. Not being able to break "fn" and "( EXPR\, EXPR )" into separate productions leaves no possible interpretation other than "sort LIST" for "sort fn( EXPR\, EXPR )".
2) If I had wanted a "sort fn( EXPR\, EXPR )" to be parsed as "sort SUBNAME LIST"\, I should be required to use unary '+' as in: "sort fn +( EXPR\, EXPR )".
3) schwern says so. :-)
$ perl-5.6.1 -wle 'sub foo { return 1..5} print sort(foo(8))' Unquoted string "foo" may clash with future reserved word at -e line 1. 8
$ perl-5.8.0 -wle 'sub foo { return 1..5} print sort(foo(8))' 12345
Bisect: ----Program---- #!/usr/bin/perl -l
sub foo { return 1..5 } print sort(foo(8))
----Output of ...l/pxZYtEz/perl-5.7.0@8238/bin/perl---- 8
----EOF ($?='0')---- ----Output of ...l/pw7q1Jw/perl-5.7.0@8239/bin/perl---- 12345
----EOF ($?='0')---- Need a perl between 8238 and 8239
http://perl5.git.perl.org/perl.git/commit/ f0670693ff29ac8dc3df00d73b858a9d736644ed author Simon Cozens \simon@​netthink\.co\.uk Wed\, 27 Dec 2000 14:12:44 +0000 (14:12 +0000) committer Jarkko Hietaniemi \jhi@​iki\.fi Thu\, 28 Dec 2000 22:37:45 +0000 (22:37 +0000) commit f0670693ff29ac8dc3df00d73b858a9d736644ed tree 8bbec927d4422331c4ad492ac366b541d861526d tree | snapshot parent a5de3055c23e1cf83512f28ca751d687d2cbd7ef commit | diff
Re: [ID 19991001.003] sort(sub(arg)) misparsed as sort sub args Message-ID: \<20001227141244.A13344@deep-dark-truthful- mirror.perlhacker.org>
p4raw-id: //depot/perl@8239
This was an intended change of behaviour. See [perl #1549].
A patch to update the documentation and add more examples has been submitted in [perl #54040].
=> Setting this one to resolved.
p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#30377 (status was 'resolved')
Searchable as RT30377$