#A list is a group of scalars (very loose definition) print "list list1: \n"; @list1 = (5, 6, 7, 8); print $list1[0],"\n"; print $list1[1],"\n"; print $list1[2],"\n"; print $list1[3],"\n"; print "\nlist list2: \n"; $x = 10; @list2 = (5, 'apple', $x, 3.14159); print $list2[0],"\n"; print $list2[1],"\n"; print $list2[2],"\n"; print $list2[3],"\n"; #qw keyword, use when you only have strings in list @trees = qw (oak cedar maple apple); print "\nlist trees: \n"; print $trees[0],"\n"; print $trees[1],"\n"; print $trees[2],"\n"; print $trees[3],"\n"; #context in Perl, lhs is scalar, rhs is array $size = @trees; print "\nlist tree has $size elements\n"; print "elements are [@trees]\n"; print "using for loop...\n"; for ($index = 0; $index<@trees; $index++) { print "$trees[$index]\n"; } #convert a scalar into an array - split function print "\nsplit function1: \n"; @words=split(/ /, "The quick brown fox"); #After you run this code, @words contains each of the words The, quick, brown, and fox—without the spaces. for ($index = 0; $index<@words; $index++) { print "$words[$index]\n"; } print "\nsplit function2: \n"; @words=split(/,/, "D,C,B,A"); #After you run this code, @words contains each of the words —without the ,. for ($index = 0; $index<@words; $index++) { print "$words[$index]\n"; } @words2 = sort @words; print "now it is sorted: ", @words2;