in reply to Perl Array - What an array contains
#!/usr/bin/perl use strict; use warnings; my @strings = ('London, Paris','','London'); foreach my $string (@strings) { my @capitals= split(/,/,$string); print "list of capitals: @capitals\n"; print "number of capitals:".@capitals."\n"; print "number of capitals:",scalar @capitals,"\n"; print "lots of capitals\n\n" if (@capitals>1); print "one or no capitals\n\n" if (@capitals <= 1); } __END__ list of capitals: London Paris number of capitals:2 number of capitals:2 lots of capitals list of capitals: number of capitals:0 number of capitals:0 one or no capitals list of capitals: London number of capitals:1 number of capitals:1 one or no capitals
|
|---|