Thread Wieviel Einträge sind im Array? (13 answers)
Opened by skontox at 2003-09-25 21:37

esskar
 2003-09-26 02:35
#56883 #56883
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=jan10001,25.09.2003, 23:48]
Code: (dl )
my $anzahl_eintraege = scalar @array;

Den Syntax verstehe ich nicht ganz, kann mir mal einer das erklären?[/quote]
perldoc -f scalar
scalar EXPR
Forces EXPR to be interpreted in scalar context and returns the
value of EXPR.

@counts = ( scalar @a, scalar @b, scalar @c );

There is no equivalent operator to force an expression to be
interpolated in list context because in practice, this is never
needed. If you really wanted to do so, however, you could use
the construction "@{[ (some expression) ]}", but usually a
simple "(some expression)" suffices.

Because "scalar" is unary operator, if you accidentally use for
EXPR a parenthesized list, this behaves as a scalar comma
expression, evaluating all but the last element in void context
and returning the final element evaluated in scalar context.
This is seldom what you want.

The following single statement:

print uc(scalar(&foo,$bar)),$baz;

is the moral equivalent of these two:

&foo;
print(uc($bar),$baz);

See perlop for more details on unary operators and the comma
operator.

View full thread Wieviel Einträge sind im Array?