Mailinglist Archive: opensuse (2532 mails)

< Previous Next >
[opensuse] Quick perl question - why are @array[$num] and $array[$num] the same?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Thu, 01 May 2008 01:52:14 -0500
  • Message-id: <4819689E.20305@xxxxxxxxxxxxxxxxxx>

I don't know who I have to thank for this, but I think it was Anders who recommended that I look at perl after one of my last weird bash questions. I have a syntax question as I go though perl.

The situation. I read a file into an array and then go to reference
each line.

my $NUM = 1;
open FILE, ".bashrc" or die $!;
my @array = <FILE>;

How is it legal that I can reference the array element either as @array[element] or $array[element]?:

while (@array[$NUM]) {
print "$NUM : @array[$NUM]\n";

while ($array[$NUM]) {
print "$NUM : $array[$NUM]\n";

From what I've read, it seems like the list $array[element] would just return the number of characters in the list $array[element] not the text itself. How should I think about this?

David C. Rankin, J.D., P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >