Answered! Write a program to print only the words in english.sorted that are all CAPS, such as the word "ANSI"….

Write a program to print only the words in english.sorted that are all CAPS, such as the word “ANSI”. You must use regular expression matching. Include the source code of your program in perl_assignment.txt.

Expert Answer

 CODE:

#
# Program to print UPPERCASE words in perl
#
my $file = ‘english.sorted’; #store name of file
open(my $fptr, ‘<:encoding(UTF-8)’, $file) #open file for reading
or die “Could not open file ‘$file’ $!”;

while (my $line = <$fptr>) #read file line by line
{
chomp $line;
while ($line =~ m/b([A-Z]+)b/g) #check for UPPERCASE words using Regex
{
print $1, “n”; #print if found
}
}

english.sorted file:

hello HELLO
ANSI C abcd Abcd adSbcsjkd
XYZ xyz
abcdefgh

OUTPUT:

Still stressed from student homework?
Get quality assistance from academic writers!