Perl Array Assignment Computerized Education Essay
A second array holds the price of each model in US Dollars.
Create a third array which contains the price of each model in Pounds Sterling. As the result print one line per model stating its cost in pounds.
The follow example initializes and uses a multidimensional array in Perl; -- actually simply an array of references.
They are more like an index in the database, or filenames in a directory.In the above example, $stuff refers to the first array reference ['one', 'two', 'three' ...], $stuff refers to the second array reference [7, 6, 5] and so on.After adding the subscript to get you to the right reference, just add another index to go to the right element in that sub-array.# Multiple elements value assignment, which creates an array with four elements, some numeric and some [email protected] = (25, "John", "Mary", -45.34); print "$array\n"; # John # Direct assignment of an element with a specific index.print $creepy- operator to access elements, and we use square brackets to initialize array references instead of round brackets for arrays, but there's not a huge difference other than that.Since references to arrays are scalar values, we can use them to form multidimensional arrays.Thus, when you assign values only to the first and, say, 1000th elements of an array, Perl will allocate memory only for two elements, not for 1000 elements.In case the elements of the array are strings, another good model of understanding of what Perl array is the buffer of the text editor.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.