Re: How do I read data passed to perl script
by phenom (Chaplain) on Jun 07, 2005 at 11:18 UTC
|
For some things, I use @ARGV, and for others, I use the Getopt::Std and Getopt::Long modules at cpan.org. It depends on what your needs are.
#!/usr/bin/perl
use strict;
use warnings;
if(@ARGV) {
print "You entered @ARGV\n";
}
| [reply] [d/l] [select] |
Re: How do I read data passed to perl script
by marto (Cardinal) on Jun 07, 2005 at 11:21 UTC
|
Hi
If you are new to Perl I suggest reading some of the many fine Tutorials the site offers. This answer to this question, and may more can be found within these Tutorials :D
Hope this helps,
Cheers
Martin | [reply] |
Re: How do I read data passed to perl script
by tlm (Prior) on Jun 07, 2005 at 11:55 UTC
|
my $arg = shift @ARGV;
is one way to do it. There are a few billion others.
But, as you say, this is a very basic question, which makes me wonder, why are you trying to do this without learning the basics of Perl first? There are sources aplenty to do this. Trying to solve a programming problem by asking piecemeal questions like this one, without knowing the basics first, seems to me a crazy way to go about it. Are you under the gun to conjure up with some Perl code out of thin air?
| [reply] [d/l] |
|
why are you trying to do this without learning the basics of Perl first?
How can he learn Perl without slinging some code? I've found, for myself, that I just cannot grab a book or whatever and "absorb" a language from scratch. I have to have some concrete problem to solve, and I learn the language as I go about solving it. Now, that means of course that if I don't need CGI in my solution that I'm not going to learn CGI, but that's what works best for me. After I have a fairly strong foundation in the language, then I can start branching out to learn things I'm not actually needing to use right away.
| [reply] |
Re: How do I read data passed to perl script
by mikeraz (Friar) on Jun 07, 2005 at 12:36 UTC
|
You're right. It is Perl 101. People have provided the answer already, so I'll indulge my curiosity. Why are you asking? Comparing Perl to other languages before deciding which one(s) to learn? Checking out how monks handle questions?
If you decide you're going to learn Perl I highly recommend spending a weekend with Learning Perl. It will get you past the crawling stage and into walking with the language quickly. After working through that book you'll be able to follow on with your own explorations. A weekend, without too many distractions, is enough time to do every problem in the book. Well, provided you have some programming background. Your question indicates that you do have that.
Be Appropriate && Follow Your Curiosity
| [reply] |
|
Indeed, my explanation is simple.
I am under some pressure to produce 'a fabulous tool' using Perl. My programming experience has been in VBScript, REXX, JCL and some other lanuages.
At the moment I have 2 books, the Tutorial page on Perl Monks open so I am trying to learn using a real world problem.
I am sorry for the basic question but after scanning the relevent pages that I could find, it was easier to post a simple message and hope that others could point me in the right direction. Which the Monks have done.
I have already test some parts to my solution like interogating MS SQL table for info..
Thanks for everyone's input...
Danny
| [reply] |
|
BTW, that's my reply above this one.... just forgot to login !!!
| [reply] |
|
|
|
Re: How do I read data passed to perl script
by thcsoft (Monk) on Jun 07, 2005 at 11:21 UTC
|
| [reply] |
Re: How do I read data passed to perl script
by rlucas (Scribe) on Jun 07, 2005 at 16:27 UTC
|
I highly recommend getting in the habit of making your programs filters. Happily, Perl has a great way to do this:
while (<>) {
# do stuff on $_ line by line
}
This will either take direct STDIN (run the program, it sits there, you enter lines of text until you hit ctrl-D), or take a list of filenames on the command line and process their contents as STDIN. Because this idiom doesn't use any textual identifier (like ARGV or STDIN), and because it's a difficult concept for a newbie to describe or search for (or even to conceive of), it's often something people don't pick up on early. I'm going to go on a limb and counsel a novitate to "just do it," and adapt your intentions to fit this idiom.
It's not exactly what you described -- the others' @ARGV solutions are for that -- but if you can alter your requirement slightly, writing programs as filters has a lot of benefits. See The Art of Unix Programming for why. | [reply] [d/l] |