Since we have an array of references (scalar values), each reference can point to an array of any length; there's no requirement for all arrays in the parent array to be the same length.As long as you keep in mind that you're actually dealing with an array of references, it's easy to remember how to access the elements.
They are more like an index in the database, or filenames in a directory.
define initial array contents @basket = ("Apple","Banana","Carrot"); print "1. add element at the end of the array push(@basket, "Orange"); print "2. add element at the beginning of the array unshift(@basket, "Avocado"); print "3. remove element from the end of the array pop(@basket); print "4. remove element from the beginning of the array shift(@basket); print "5.
My \@basket array is: @basket\n"; @Months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; @winter_canada = @Months[-1,0,1]; @winter_brazil = @Months[5..7]; print "winter months in Canada are: @winter_canada\n"; # Dec Jan Feb print "winter months in Brazil are: @winter_brazil\n"; # Jun Jul Aug $Months = 'Jan, Feb, Mar,apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec'; @array_of_month_names = split(',' , $Months); $dash_delimited_monthlist = join('-' , @array_of_month_names); $very_long_message = join(' is followed by ' , @array_of_month_names); print "$Months\n"; print "@array_of_month_names\n"; print "$dash_delimited_monthlist\n"; print "$very_long_message\n"; An array holds a list of cellular phone models.
Like in text editor you can delete element of array with particular index by "undefying" them.
For example: As we already mentioned, it's very important to understand that Perl arrays should be considered not as arrays in compiled languages like Fortran and C, but as an attempt to introduce a concept of programmable editor buffer (with indexes as line number) into the programming language.