1. Computing

Using Quote Word

How to use quote word in Perl

From , former About.com Guide

Perl has a lot of handy, built-in shorthand for some of the more common expressions and structures. For example, a list is often made up of single words or elements, and writing all that data out in the normal fashion can quickly become cumbersome and difficult to read:

@myNames = ('Jacob', 'Michael', 'Joshua', 'Matthew', 'Alexander', 'Andrew');
The longer the list, the more you find yourself typing out commas and quotes to separate each element.

Fortunately, Perl has a built-in quote word function that makes those single word lists easier to read and write:


@myNames = qw(Jacob Michael Joshua Matthew Alexander Andrew);
The quote word function qw(STRING) takes each element in the string passed to it and splits it on the white space, placing each item into an array element. You'll find that it's often written out as in the following example:

@myNames = qw/Jacob Michael Joshua Matthew Alexander Andrew/;

©2013 About.com. All rights reserved.