pico arraylistslices1.pl
#!/usr/bin/perl -w
#Lists, Slices, Ranges
#scalars (single values), Array (lists), Hashes (key/value pairs)
print (qw(boston miami santaclara));#qw - devine a list of values that are not separated by spaces and are strings
#END
perl -w arraylistslices1.pl # prints -> bostonmiamisantaclara
print (qw(boston miami santaclara) [0,1]); # prints -> bostonmiami
print (qw(boston miami santaclara) [0,1,2]); # prints -> bostonmiamisantaclara
print (qw(boston miami santaclara) [0..2]); #Ranges: prints -> bostonmiamisantaclara
my @uscities = qw(boston charlote newark miami);#list
print "@uscities\n"; # prints ->boston charlote newark miami
print "@uscities[0,1]\n"; # prints ->boston charlote
print "@uscities[0..2]\n"; # prints ->boston charlote newark
print "@uscities[0..$#uscities]\n"; # prints all elements ->boston charlote newark miami
my @uscities = qw(boston charlote newark miami austin dallas huston);#list
my @eastcoastcities = @uscities[0..3];
print @eastcoastcities; prints -> boston charlote newark miami
print @eastcoastcities[2..$#eastcoastcities]; prints -> newark miami austin dallas huston
my @eastcoastcities = @uscities[0..3,4,5];
print @eastcoastcities; prints -> boston charlote newark miami austin dallas
No comments:
Post a Comment