Thread Programmierstil (24 answers)
Opened by kruemmel at 2007-07-27 10:38

kristian
 2007-07-29 12:39
#78981 #78981
User since
2005-04-14
684 Artikel
BenutzerIn
[Homepage] [default_avatar]
Hallo

Code: (dl )
1
2
3
4
5
6
sub XYZ {
my @array = 1..100;
defined( wantarray )
? return @array
: return \@array;
}


perldoc -f wantarray

Quote
Returns true if the context of the currently executing subroutine or "eval" is looking for a list value.
Returns false if the context is looking for a scalar.
Returns the undefined value if the context is looking for no value (void context).


Also eher so:
Code: (dl )
1
2
return unless defined wantarray;
return wantarray ? @array : \@array;


Gruss
Kristian

View full thread Programmierstil