[Linux & perl] Command line arguments

  • Thread starter Thread starter rama1001
  • Start date Start date
  • Tags Tags
    Line Linux
Click For Summary

Discussion Overview

The discussion revolves around understanding command line arguments in Perl, specifically the use of the @ARGV array. Participants explore the concept of command line arguments, their implementation in a Perl script, and their practical applications.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant expresses confusion about command line arguments and seeks basic information on how Perl accesses them through @ARGV.
  • Another participant suggests a practical example by running a script with command line arguments to demonstrate how they are passed to the program.
  • A different participant questions the practical utility of command line arguments beyond simply printing them.
  • One response clarifies that command line arguments allow scripts to function similarly to Unix/Linux commands, enhancing their flexibility.
  • Another participant provides examples of using command line arguments with the 'ls' command to illustrate how different arguments can alter the output.

Areas of Agreement / Disagreement

Participants generally agree on the basic functionality of command line arguments in Perl, but there is some uncertainty regarding their practical applications and usefulness in real-world scenarios.

Contextual Notes

Some assumptions about the user's prior knowledge of command line operations and Perl scripting may be missing. The discussion does not resolve how command line arguments can be effectively utilized in various contexts.

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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 12 ·
Replies
12
Views
11K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
4K