ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I think it will be easier for me to show you all what I am trying to do rather than trying to explain it, so here it is:
echo "hello world" | perl -e 'print $ARGV';
Why does this not work. I have been looking all over the web for a reason, but I have not found much documentation pertaining to using perl from the command line. So web resources would be useful to me too.
Well, what are you trying to do? Count arguments? $#ARGV. Look at arguments? @ARGV. $ARGV is set to the input file when reading from <>. In the case above, you are not reading from any file.
I think this is a good question and it involves several important concepts that are specific to perl. So what you're trying to do is print "hello world." The mistake in your code is that you are confusing piping some input to the program and giving arguments on the command line. Also you have some confusion over the use of @ARGV, and scalar/list context.
So, what I'll do is post several ways to do what you want. Please investigate them! If you have any questions, please ask.
"When you read lines from <>, it magically gives you all the lines from all the files mentioned on the command line. If no files were mentioned, it gives you standard input instead, so your program is easy to insert into the middle of a pipeline of processes."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.