Write a Perl program named states.pl that creates a scalar value $states with the value "Mississippi Ala- bama Texas Massachusetts Kansas". Using only the techniques discussed in this chapter, write a program that does the following:
a) Search for a word in scalar $states that ends in xas. Store this word in element 0 of an array named @state-
sArray.
b) Search for a word in $states that begins with k and ends in s. Perform a case-insensitive comparison. Store this
word in element 1 of @statesArray.
c) Search for a word in $states that begins with M and ends in s. Store this element in element 2 of the array.
d) Search for a word in $states that ends in a. Store this word in element 3 of the array.
e) Search for a word in $states at the beginning of the string that begins with M. Store this word at element 4 of the
array.
f) Output the array @statesArray to the screen.
```
1 # Exercise 29.7
2
3 $states = "Mississippi Alabama Texas Massachusetts Kansas";
4
5 if ( $states =~ /\b(\w+xas)\b/ ) {
6 $statesArray[ 0 ] = $1;
7 }
8
9 if ( $states =~ /\b(k\w+s)\b/i ) {
10 $statesArray[ 1 ] = $1;
11 }
12
13 if ( $states =~ /\b(M\w+s)\b/ ) {
14 $statesArray[ 2 ] = $1;
15 }
16
17 if ( $states =~ /\b(\w+a)\b/ ) {
18 $statesArray[ 3 ] = $1;
19 }
20
21 if ( $states =~ /\b(^M\w+)\b/ ) {
22 $statesArray[ 4 ] = $1;
23 }
24
25 print "@statesArray";
```
Texas Kansas Massachusetts Alabama Mississippi
You might also like to view...
Only an administrator account user can make changes that affect other users
Indicate whether the statement is true or false
Which of the following Word 2010 features reveals hidden data in a file?
A) Document Inspector B) Compatibility Checker C) Document Properties D) Document Panel
Each processor core on a multi-core processor generally runs faster than a single-core processor.
Answer the following statement true (T) or false (F)
Describe how (and why) the Internet moved from government-funded projects to the private sector.
What will be an ideal response?