in reply to Scalar value @scores_sorted[$i] better written as $scores_sorted[$i]

The sigil to use is the type being returned.

$foo # Scalar $foo[$i] # Array element, a scalar $foo{$k} # Hash element, a scalar @foo # Array contents, a list of scalar values @foo[$i, $j] # Array slice, a list of scalar values @foo{$k1, $k2} # Hash slice, a list of scalar values %foo # Hash contents, a list of key-value pairs

$foo[EXPR] and @foo[EXPR] differ in the context in which EXPR is evaluated, and they differ in the number of scalars they can return.

Replies are listed 'Best First'.
Re^2: Scalar value @scores_sorted[$i] better written as $scores_sorted[$i]
by JavaFan (Canon) on Jan 03, 2011 at 13:22 UTC
    The sigil to use is the type being returned
    Actually, it isn't. Here are some counter examples:
    @foo # Number of elements of the array. @foo # A reference to the array. @foo[$i, $j] # Last element of slice. @foo{$k1, $k2} # Last element of slice. %foo # A reference to the hash. %foo # True/false. %foo # String with ratio of filled buckets and buckets.
    The sigil can influence what is returned, but foremost, it's the context that will determine what is returned. In particular, in scalar context, a scalar will always be returned.
      The counter examples fall into two categories: scalar context, where nothing but a scalar can be returned, and where rules are used to make the variable an lvalue.
        I'd say scalar context is common enough in Perl to debunk the entire The sigil to use is the type being returned statement.