Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.1 Array Variables

Each variable in Perl starts with a special character that identifies what type of variable it is. We saw that scalar variables always start with a `$'. Similarly, all array variables start with the character, `@', under the same naming rules that are used for scalar variables.

Of course, we cannot do much with a variable if we cannot assign things to it, so the assignment operator works as perfectly with arrays as it did with scalars. We must be sure, though, to always make the right hand side of the assignment a list, not a scalar! Here are a few examples:

use strict; my @stuff = qw/a b c/; # @stuff a three element list my @things = (1, 2, 3, 4); # @things is a four element list my $oneThing = "all alone"; my @allOfIt = (@stuff, $oneThing, @things); # @allOfIt has 8 elements!

Note the cute thing we can do with the () when assigning @allOfIt. When using (), Perl allows us to insert other variables in the list. These variables can be either scalar or array variables! So, you can quickly build up a new list by "concatenating" other lists and scalar variables together. Then, that new list can be assigned to a new array, or used in any other way that list literals can be used.




 
 
  Published under the terms of the GNU General Public License Design by Interspire