|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
PERL
DETAILS
Question: How do I read command-line arguments with Perl?
Answer: With Perl, command-line arguments are stored in the array named @ARGV. $ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc. $#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1. Here's a simple program: #!/usr/bin/perl $numArgs = $#ARGV + 1; print "thanks, you gave me $numArgs command-line arguments.
"; foreach $argnum (0 .. $#ARGV) { print "$ARGV[$argnum]
"; }
|
|
|
Category |
Perl Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 8144 users |
Added on |
10/28/2014 |
Views |
71726 |
Rate it! |
|
|
Question:
How do I read command-line arguments with Perl?
Answer:
With Perl, command-line arguments are stored in the array named @ARGV. $ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc. $#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1. Here's a simple program: #!/usr/bin/perl $numArgs = $#ARGV + 1; print "thanks, you gave me $numArgs command-line arguments.
"; foreach $argnum (0 .. $#ARGV) { print "$ARGV[$argnum]
"; } Source: CoolInterview.com
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 |
|
When would `local $_' in a function ruin your day?
|
View Answer
|
|
What happens to objects lost in "unreachable" memory..... ?
|
View Answer
|
|
How do you match one letter in the current locale?
|
View Answer
|
|
How do I print the entire contents of an array with Perl?
|
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
|