We started working with strings in the scalar tutorial. Since a list is just an ordered group of scalars, you can also create lists of strings. In fact, we've already seen some examples of this at the start of the tutorial. Just like a string going into a scalar, you use the single or double quotes to contain it.
@myNames = ('Larry', 'Curly', 'Moe');The same rules for single and double quote apply to strings in lists.
#!/usr/local/bin/perlTry running the program, and you'll see that it prints out exactly as the individual strings in the other tutorial.
@myStrings = (
'It\'s necessary to escape the single quote.',
"It's fine to leave a single quote free.\n A \" and a \\ must be escaped.\n"
);
print @myStrings;
There's another handy shorthand you can use for lists of words that can save some typing. Rather than assigning the array like this:
@myNames = ('Larry', 'Curly', 'Moe');Use the quote word shorthand that splits the data in the parentheses by spaces:
@myNames = qw(Larry Curly Moe);Next: Playing With Lists
