in reply to Re: Perl list items
in thread Perl list items
To elaborate on davido's good answer, if you had used ( $A ) = @A instead, @A would have been evaluated in list context and $A would have the value of the first element of $A, which could have also been written as $A (i.e., the 1st element of @A).
Part of my point in writing all these different versions of A is to demonstrate that choosing the same name for a scalar and an array is confusing. It is much more readable to have distinct, concise, yet descriptive names.
One more thing... When troubleshooting your code, it can be helpful to print the contents of your variables to make sure things look as expected. This is simplest for scalars. For more complex structures, Data::Dumper and Data::Printer are very handy. I prefer Data::Printer since you need to type less, there is auto-indexing and pretty color coding. Here is a usage example (it is more impressive on complex hashes, etc.):