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

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.
  • Comment on Re^2: Scalar value @scores_sorted[$i] better written as $scores_sorted[$i]
  • Download Code

Replies are listed 'Best First'.
Re^3: Scalar value @scores_sorted[$i] better written as $scores_sorted[$i]
by ikegami (Patriarch) on Jan 03, 2011 at 14:53 UTC
    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.