Trying to do completly stupid stuff with perl I tried to do the
following:
xyzzy% perl -le 'sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1)'
xyzzy%
Somehow the print statement isn't evaled. Playing a little more around
I tried the following:
xyzzy% perl -le '(sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1))'
xyzzy% perl -le '(sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1))[3]'
a:2 b:5
a:3 b:5
a:3 b:2
a:4 b:5
a:4 b:3
a:1 b:5
a:1 b:4
a:1 b:3
a:1 b:2
xyzzy% perl -le 'print sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1)'
a:2 b:5
a:3 b:5
a:3 b:2
a:4 b:5
a:4 b:3
a:1 b:5
a:1 b:4
a:1 b:3
a:1 b:2
12345
xyzzy% perl -le 'print(sort {print "a:$a\tb:$b"; $a cmp $b} qw(5 2 3 4 1))'
a:2 b:5
a:3 b:5
a:3 b:2
a:4 b:5
a:4 b:3
a:1 b:5
a:1 b:4
a:1 b:3
a:1 b:2
12345
xyzzy%
So the question is when does sort just ignores the sideeffects and
when is they evaled?
I have yet to find a usefull purpose for having side effects in the
sort statement but that is not the point here.
--
Emacs er det eneste moderne styresystem der ikke er multitr�det.