Perl qw Function



Description

This function is a quick way to specify a lot of little single-quoted words. For example, qw(foo bar baz) is equivalent to ('foo', 'bar', 'baz'). Some programmers feel that using qw make Perl scripts easier to read. You can actually use any set of delimiters, not just the parentheses.

Simply you can use qw() to prepare an array as shown in the example below.

Syntax

Following is the simple syntax for this function −

qw EXPR

Return Value

This function return a list consisting of the element of LIST evaluated as if they were single-quoted.

Example

Following is the example code showing its basic usage −

#!/usr/bin/perl -w

@array = qw(This is a list of words without interpolation);

foreach $key (@array) {
   print"Key is $key\n";
}

When above code is executed, it produces the following result −

Key is This
Key is is
Key is a
Key is list
Key is of
Key is words
Key is without
Key is interpolation
perl_function_references.htm
Advertisements