Mailinglist Archive: opensuse (2532 mails)

< Previous Next >
Re: [opensuse] Quick perl question - why are @array[$num] and $array[$num] the same?
  • From: Jan Engelhardt <jengelh@xxxxxxxxxx>
  • Date: Thu, 1 May 2008 09:51:19 +0200 (CEST)
  • Message-id: <alpine.LNX.1.10.0805010949250.5623@xxxxxxxxxxxxxxxxxxxxxxxxx>

On Thursday 2008-05-01 08:52, David C. Rankin wrote:

Quick perl question - why are @array[$num] and
$array[$num] the same?

They are not.
As per the perl manual or so, $ denotes the singular form, and
@ the plural form. Like, $apple but @apples.
IOW, $a[2] to extract one element, and @a[2,3,4] to extract three (same
with hashes: $a{onething}, @a{one,another}).
Of course, @a[2] should be valid just in case the list passed in has
only one element. (Allows you to write something like
@a[&all_interesting_indexes($of_this_array)]
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
References