Perl Arguements

P

Paul

I am having difficulty in getting the Perl Interpretor to recognize
arguements submitted with a perl script. For example,I have a simple
perl script like this called temp.pl

print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";

If I run the script as 'temp.pl A B C',I get the following output:
ARGV0 :
ARGV1 :
ARGV2 :

If I run the script as 'perl temp.pl A B C', the arguements are then
recognized and I get the following output:
ARGV0 : A
ARGV1 : B
ARGV2 : C

I do not understand why the difference, the perl scripts is running in
both cases, but in the first case no arguements seem to be recognized.

Thanks for any help, Paul
 
M

Michael P. Broida

Paul said:
I am having difficulty in getting the Perl Interpretor to recognize
arguements submitted with a perl script. For example,I have a simple
perl script like this called temp.pl

print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";

If I run the script as 'temp.pl A B C',I get the following output:
ARGV0 :
ARGV1 :
ARGV2 :

If I run the script as 'perl temp.pl A B C', the arguements are then
recognized and I get the following output:
ARGV0 : A
ARGV1 : B
ARGV2 : C

I do not understand why the difference, the perl scripts is running in
both cases, but in the first case no arguements seem to be recognized.

Do you have the "shebang" line at the beginning?
#!/usr/bin/perl

I'm thinking that if you DON'T have that line and you
run it without specifying "perl", then it's running
as commands to a shell (not executing "perl") which
-might- output what you see.
(Or maybe not; it's just a thought. I'm on Win32, so
can't test this theory.)

Mike
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Do you have the "shebang" line at the beginning?
#!/usr/bin/perl

I'm thinking that if you DON'T have that line and you
run it without specifying "perl", then it's running
as commands to a shell (not executing "perl") which
-might- output what you see.

My shell, bash, says "print: command not found" or some such.
(Or maybe not; it's just a thought. I'm on Win32, so
can't test this theory.)

Why not? Doesn't Win32 have a command shell?

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj9dOQIACgkQhVcNCxZ5ID+m3ACfVtGQzjZ6IHJ5splaDuHNyKG4
lg0AnA0gf0WXJOFYzQ5LAid07XQYfSZL
=qpKN
-----END PGP SIGNATURE-----
 
S

Sam Holden

My shell, bash, says "print: command not found" or some such.

Korn shell has a print command, and it is a reasonably popular shell.
It does say "-might-" after all.
Why not? Doesn't Win32 have a command shell?

Not one that will execute files with arbitrary names. And clearly testing
such a thing would be pointless since the OP isn't using the a windows
command shell (since it won't produce the behaviour described).
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It has, but .pl is associated with perl so even without the she bang a
.pl script is executed as perl.

without an extension:

(1)

D:\Snippets>arg hello world
'arg' is not recognized as an internal or external command,
operable program or batch file.

[snip]

Both you and Sam make good points--though I think Sam's
is slightly more valid, since neither your nor my error
messages look like the OPs. I don't have ksh available,
so I can't test whether that would produce the aberrant
behaviour the OP had.
^ please use the appropriate sig separator which is -- followed by one
space. This means that most news readers automatically can remove the 12
(not counting the sig sep) lines which includes the PGP signature. Thanks.

Well, I have made a conscious decision to not use the switch
to gpg that preserves the "-- " delimiter; according to the
man page it causes some problems with spaces. I apologize
for this nonstandard behaviour. Some newsreaders (like slrn)
can strip this nonstandard sig delimiter.

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj9dVkQACgkQhVcNCxZ5ID8ZMACcD4S40O4LuoyMXfaWa94bkwAd
OSgAn0HCVu2VRv1WeUZ//lhhMAQyesWa
=zpGZ
-----END PGP SIGNATURE-----
 
P

Paul

Tina Mueller said:
Paul said:
I am having difficulty in getting the Perl Interpretor to recognize
arguements submitted with a perl script. For example,I have a simple
perl script like this called temp.pl
print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";
If I run the script as 'temp.pl A B C',I get the following output:
ARGV0 :
ARGV1 :
ARGV2 :

which operating sytem, which perl version?
If I run the script as 'perl temp.pl A B C', the arguements are then
recognized and I get the following output:
ARGV0 : A
ARGV1 : B
ARGV2 : C
I do not understand why the difference, the perl scripts is running in
both cases, but in the first case no arguements seem to be recognized.

i don't understand the difference, either. for me it works, if
i call the script with ./temp.pl (if the rights are set correctly):

$ cat temp.pl
#!/usr/bin/perl -w
use strict;
print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";
$ ls -l temp.pl
-rwxr--r-- 1 tina users 115 Sep 8 23:27 temp.pl
$ temp.pl A B C
bash: temp.pl: command not found
$ ./temp.pl A B C
ARGV0 : A
ARGV1 : B
ARGV2 : C

hth, tina

Tina,

I am running this on Win 2k, the Perl is Active State 5.2.2.0.

Thks,
Paul
 
M

Michael P. Broida

Keith said:
My shell, bash, says "print: command not found" or some such.


Why not? Doesn't Win32 have a command shell?

Not one that could pay attention to the "shebang" line
INSIDE the file.

Here on Win2K, there is a "print" command; I could have
tested that, BUT our network printer queue management
system doesn't work well from the DOS (CommandPrompt)
side.

Mike
 
M

Michael P. Broida

John said:
And for those who really want the same experience on Windows:
http://www.cygwin.com/

I am interested in Cygwin, but we need to keep all of
our systems here in pretty nearly the same configuration
so we don't introduce problems from dependencies on a
particular tool.

We had problems on an older project under Solaris when
one person decided to use "tcsh" instead of our "standard"
csh. Some of his scripts didn't work correctly for the
rest of us or for our customers. :) So we enforce a
standard set of tools.

Mike
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

I am running this on Win 2k, the Perl is Active State 5.2.2.0.

Might adding a

use warnings;

statement be helpful?

--keith

--
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj9eMDgACgkQhVcNCxZ5ID+TiQCggO79bh0IHToJzqK+hVeGEJqh
xTYAnR1aRHuErPZ3lYTdy2an9KNqxlPA
=1eLw
-----END PGP SIGNATURE-----
 
B

Bart Lateur

Michael said:
We had problems on an older project under Solaris when
one person decided to use "tcsh" instead of our "standard"
csh. Some of his scripts didn't work correctly for the
rest of us or for our customers. :)

That's what the shebang line is for.
 
M

Michael P. Broida

John said:
So why can you use tool Perl but not tool Cygwin?

Perl has been approved. Cygwin has not.
I don't do the approving, so I don't know their reasons.

Mike
 
M

Michael P. Broida

Bart said:
That's what the shebang line is for.

Yeah, but... (It's been 7+ years, so my recall is a bit
spotty...)

The problem surfaced when the user's DEFAULT shell was tcsh.
We tracked it down to some builtin function that behaved VERY
slightly differently in tcsh than in csh. I don't recall now
which function it was, but that TINY difference screwed up one
of:
- the setup commands we required in the .login/.cshrc files
- the actual startup scripts for the project app
I don't recall which.

The simple fix was to require csh for all testing/running of
that app. NONE of our customers were "techie" enough to find
or use tcsh themselves; it was only ONE of our developers that
liked using it. :) He was able to use tcsh for his general
work as long as he set his default shell to csh and opened a
fresh csh for testing/running.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top