[Linux & perl] Command line arguments

  • Thread starter Thread starter rama1001
  • Start date Start date
  • Tags Tags
    Line Linux
AI Thread Summary
Command line arguments are inputs provided to a script at the time of execution, allowing for dynamic interaction with the program. In Perl, these arguments are accessed using the special array @ARGV. For example, if a script named args.pl is executed with the command "./args.pl one two three," the output will display "one," "two," and "three," which are the command line arguments. This functionality is crucial as it enables scripts to behave similarly to Unix/Linux commands, allowing users to customize their execution. The ability to pass different arguments can alter the script's behavior, making it more versatile and practical for various tasks, akin to how commands like "ls" can produce different outputs based on the provided arguments.
rama1001
Messages
130
Reaction score
1
Hi,
I am in process of leraning Linux. I have been structed in understanding of command line arguments and @ARGV in perl.
What is command line arguments? Really, i have no idea.
Though, i have implemented a short program in perl to list this command line arguments but i couldn't see any list when i run my program.

#! /usr/bin/perl

foreach (@ARGV) {
print "$_\n";
}


Can anyone help with basic information what does this command line arguments and how the perl is accessing them?

Thank you.
 
Technology news on Phys.org
Suppose you have the script stored in a file named args.pl. Then type this at the command prompt:

./args.pl one two three

What do you see? ("one two three" are the command line arguments to the script)
 
Yes, this i understood before itself. What is use of this? if it prints argumetns then what? How it would be useful in practically?
 
it's just a demonstration of how to get the command line arguments, without regard to how you're going to use them.

By using command-line arguments, you can write scripts that behave like Unix/Linux command-line commands.
 
Type at your command prompt:

ls

ls *.pl

ls -al

It is the same command (list) but in each case output is different - thanks to the command argument.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Replies
10
Views
2K
Replies
1
Views
4K
Replies
2
Views
1K
Replies
17
Views
3K
Replies
12
Views
11K
Replies
11
Views
5K
Replies
1
Views
4K
Back
Top