|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
PERL
DETAILS
Question: How do I print the entire contents of an array with Perl?
Answer: To answer this question, we first need a sample array. Let's assume that you have an array that contains the name of baseball teams, like this: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); If you just want to print the array with the array members separated by blank spaces, you can just print the array like this: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); print "@teams
"; But that's not usually the case. More often, you want each element printed on a separate line. To achieve this, you can use this code: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); foreach (@teams) { print "$_
"; }
|
|
|
Category |
Perl Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6645 users |
Added on |
10/28/2014 |
Views |
67951 |
Rate it! |
|
|
Question:
How do I print the entire contents of an array with Perl?
Answer:
To answer this question, we first need a sample array. Let's assume that you have an array that contains the name of baseball teams, like this: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); If you just want to print the array with the array members separated by blank spaces, you can just print the array like this: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); print "@teams
"; But that's not usually the case. More often, you want each element printed on a separate line. To achieve this, you can use this code: @teams = ('cubs', 'reds', 'yankees', 'dodgers'); foreach (@teams) { print "$_
"; } Source: CoolInterview.com
print join(",",@arr); Source: CoolInterview.com
Answered by: Valli | Date: 7/22/2010
| Contact Valli
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?
|
View Answer
|
|
How many ways can we express string in Perl?
|
View Answer
|
|
How do you give functions private variables that retain their values between calls?
|
View Answer
|
|
Describe about the security vulnerability of PHP?
|
View Answer
|
|
Explain about returning values from subroutines (functions)?
|
View Answer
|
|
Determine the difference between my and local?
|
View Answer
|
|
What are the different types of eval statements?
|
View Answer
|
|
What are the different forms of goto in perl? Explain?
|
View Answer
|
|
What is a short circuit operator?
|
View Answer
|
|
Which has the highest precedence, List or Terms? Explain?
|
View Answer
|
|
What are the different types of perl operators?
|
View Answer
|
|
What is meant by splicing arrays explain in context of list and scalar.
|
View Answer
|
|
How do you work with array slices?
|
View Answer
|
|
What are the three ways to empty an array?
|
View Answer
|
|
What exactly is grooving and shortening of the array?
|
View Answer
|
|
How to use the command shift?
|
View Answer
|
|
Is there any way to add two arrays together?
|
View Answer
|
|
Explain about Typeglobs?
|
View Answer
|
|
How does a “grep” function perform?
|
View Answer
|
|
Explain about an ivalue?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Perl Interview Questions & Answers - Exam Mode /
Learning Mode
|