1. Home
  2. Computing & Technology
  3. Perl

Using Quote Word
How to use quote word in Perl

by Kirk Brown
for About.com

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/;
Explore Perl
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Perl
  4. Perl Tutorials
  5. Perl quote word tutorial - Quoting a list of words in perl, learn how to use the quote word function.>

©2009 About.com, a part of The New York Times Company.

All rights reserved.