< Perl Programming < Keywords

The qw keyword

qw is a command that can be used to replace the quotation mark (") symbol.

Syntax

  qw(element [element] […])

Examples

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
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.