Re: Passing Variable to Perl script


Subject: Re: Passing Variable to Perl script
From: Michael Fowler (michael@shoebox.net)
Date: Wed Oct 23 2002 - 11:24:21 AKDT


On Tue, Oct 22, 2002 at 02:48:52PM -0800, bthundereagle@aidea.org wrote:
[snip]
> system (`/sqltest/perl/date.pl $file`);
> (I also tried)
> system (`/sqltest/perl/date.pl "$file"`);

You're mixing two seperate calls to an external program.

Backticks, the ``, calls a program and returns the output. system() calls a
program and returns the status. What you basically have is system() calling
the output of date.pl as if it were another program.

So, you have to choose one, system() or backticks, depending on your needs.

If you choose system, the syntax would be:

    system("/sqltest/perl/date.pl", $file);

I'm assuming $file is a filename, and you don't want it interpreted by the
shell, so I used the list form of system().

If you choose backticks, the syntax would be:

    `/sqltest/perl/date.pl \Q$file\E`

Again, I'm assuming $file is a filename, and you don't want it interpreted
by the shell, so I escaped, with the \Q...\E, any characters that may be
interpreted specially.

 
> Then after passing the variable, how do I access it? I have tried using
> %1, %%1, and $1 but so far have been unsuccessful.

Command-line arguments are in @ARGV. Thus, the first argument would be
$ARGV[0].

For documentation on system() see perldoc -f system. You can also view it
on the web at http://www.perldoc.com/perl5.6/pod/func/system.html.

For documentation on backticks see perldoc -f qx, and follow the reference
mentioned. You can also view it on the web at
http://www.perldoc.com/perl5.6/pod/perlop.html#Quote-and-Quote-like-Operators.

For documentation on @ARGV see perldoc perlvar. You can also view it on the
web at http://www.perldoc.com/perl5.6/pod/perlvar.html.

The documentation URLs above are for Perl 5.6 (5.6.0, 5.6.1). If you're
using a different version go to www.perldoc.com and select the version you
want.

The questions you're asking are fairly basic. You may want to get your
hands on some learning material such as _Learning Perl_ or _Beginning Perl_.
See learn.perl.org for more references.

Michael

--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

--------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.



This archive was generated by hypermail 2a23 : Wed Oct 23 2002 - 11:22:53 AKDT