String list operator - qw()
String list operator is a operator to create list of strings easily. You can create a list of strings without writing single quotes and commas.
qw(string1 string2 string3)
The following is an example of the string list operator. The return value is assigned to array.
my @strings = qw(cat dog mouse);
This is the same as the following list of strings.
my @strings = ('cat', 'dog', 'mouse');
You can also use characters other than "(" and ")" to create a list of strings.
qw(cat dog mouse) qw/cat dog mouse/ qw{cat dog mouse} qw#cat dog mouse# qw[cat dog mouse] qw!cat dog mouse!
Example program
This is an example program that uses the string list operator.
use strict; use warnings; # String list operator my @strings = qw(cat dog mouse); # Same meaning as ('cat', 'dog', 'mouse') print "1: String list\n"; print join(',', @strings) . "\n";
Reference: join function
Output:
1: String list cat,dog,mouse