FAQ
After reviewing http://rt.perl.org/rt3/Ticket/Display.html?id=9528,
which is blissfully free of wandering straw men, while touching on
all sort extension issues (truncated sort, to have explicit min/max
functions instead of delivering anything in scalar context), here's a
patch that adds a runtime sort-in-scalar-context warning, which, had it
existed in June of 2002, would have reported the situation that was
misinterpreted as bug 9528.

Before:
./perl -wle 'sub foo { return sort("dog", "cat", "fish") } $x = foo();\
print $x'
Use of uninitialized value $x in print at -e line 1.

After:
./perl -wle 'sub foo { return sort("dog", "cat", "fish") } $x = foo();\
print $x'
sort called in dynamic non-array context, try ()=sort ... at -e line 1.
Use of uninitialized value $x in print at -e line 1.




--- perl-current/pp_sort.c Sat Jul 31 11:44:58 2004
+++ dynamic-sort-in-scalar-warning/pp_sort.c Mon Aug 2 23:01:55 2004
@@ -1508,8 +1508,13 @@
void (*sortsvp)(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp)
= Perl_sortsv;

if (gimme != G_ARRAY) {
+ Perl_warner(
+ aTHX_ packWARN3(WARN_VOID,WARN_AMBIGUOUS,WARN_SYNTAX),
+ "sort called in dynamic non-array context,"
+ " try ()=sort ..."
+ );
SP = MARK;
RETPUSHUNDEF;
}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedAug 3, '04 at 4:14a
activeAug 3, '04 at 4:14a
posts1
users1
websiteperl.org

1 user in discussion

David nicol: 1 post

People

Translate

site design / logo © 2022 Grokbase