Dr. Dobb’s Journal in its Linux and open source section is running an article by Emmett Dulaney with 50 Perl questions and answers. The focus is mainly on the knowledge of the language itself with questions like:
- What is the simplest type of data that Perl can work with?
- Which operator can be used to take the bottom item from an array?
- You want to close the directory handle EVAN. Which of the following should you use to accomplish this?
- You want your script to read in a value from the keyboard for a variable named $duo. What do you set $duo equal to in the program to have it read a keyboard value? __________ (Fill in the blank.)
- Your script has just read in a variable from the keyboard and you want to strip that variable of the newline character that came in. What operator should you use to perform this operation?
Answers are available on Dr. Dobb’s Journal site.
7 Comments on Perl self-test questions
Which operator can be used to take the bottom item from an array?
Ans: -1
for eg : @Array=(5,6,7,”eight”);
print “$Array[-1]“;
# will give last element, also $#
You want to close the directory handle EVAN. Which of the following should you use to accomplish this?
Ans: closedir(EVAN);
You want your script to read in a value from the keyboard for a variable named $duo. What do you set $duo equal to in the program to have it read a keyboard value? __________ (Fill in the blank.)
Ans: $duo=;
chomp $duo;
You want your script to read in a value from the keyboard for a variable named $duo. What do you set $duo equal to in the program to have it read a keyboard value? __________ (Fill in the blank.)
Ans: $duo=;
chomp $duo;
You want your script to read in a value from the keyboard for a variable named $duo. What do you set $duo equal to in the program to have it read a keyboard value? __________ (Fill in the blank.)
Ans: STDIN in diamond operator
What is the simplest type of data that Perl can work with?
Ans: scalar
How will you execute a shell process from perl? eg: who >> name.txt
Ans: system (”who >> name.txt”);
One Trackback
[...] published a list of Perl self-test questions by Emmett Dulaney. Check it out to test your Perl knowledge. Checking out Dulaney’s [...]