Thread wantarray und return undef (20 answers)
Opened by rosti at 2012-02-10 13:15

pq
 2012-02-10 20:48
#156044 #156044
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
2012-02-10T19:08:47 GUIfreund
Und eine Liste ergibt im skalaren Kontext die Anzahl der Elemente.

das stimmt nicht.
eine liste im skalaren kontext gibt es im prinzip gar nicht.
es gibt arrays im skalaren kontext. dieses liefert dann die anzahl der elemente.

der komma-operator, aber auch listslices, liefern im skalaren kontext das letzte element.
Code: (dl )
1
2
3
4
5
6
7
$ perl -wE'
sub foo { return 6,7,8 }
say scalar foo()'
8
$ perl -wE'sub foo { my @a = (6,7,8); return @a[1,2] }
say scalar foo()'
8
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread wantarray und return undef