Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What is the difference between @ARGV and asking the user for input?

$num = $ARGV[0];

and

$_ = <STDIN>;

Either way a user has to put an input isn't it?

How are they different?

share|improve this question

closed as off topic by Michael Mrozek Jun 7 '13 at 2:41

Questions on Unix & Linux Stack Exchange are expected to relate to Unix or Linux within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

They don't address the same needs for the program.

A command-line argument is known by the program at the moment it starts. Getting a input from a user through stdin can be done at any moment of the execution of the program. What the user inputs could depend on what the program had output so far.

And command line arguments are usually short inputs whereas through stdin you can get any content, for example if a user redirects the standard input from a file.

Usually, command-line arguments are options for the program whereas sandard input are data to be processed. Sometimes, you can use one or the other and do the same thing, sometimes not.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.