Perl Programming/Keywords/qw
Appearance
The qw keyword
[edit | edit source]qw is a command that can be used to replace the quotation mark (") symbol.
Syntax
[edit | edit source] qw(element [element] […])
Examples
[edit | edit source] The code
my @array = qw(one two three);
print "Array contains " . @array . " element" . ((@array == 1) ? "" : "s") . "\n";
my @array1 = "only";
print "Array1 contains " . @array1 . " element" . ((@array1 == 1) ? "" : "s") . "\n";
my @family = "father, mother, daughter, son";
print "The family has " . @family . " member" . ((@family == 1) ? "" : "s") . "\n";
print qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[2] . "\n";
returns the number of elements in the arrays and the third month as follows:
Array contains 3 elements Array1 contains 1 element The family has 1 member Mar