[30312] in Perl-Users-Digest
Perl-Users Digest, Issue: 1555 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 19 09:09:48 2008
Date: Mon, 19 May 2008 06:09:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 19 May 2008 Volume: 11 Number: 1555
Today's topics:
ARGV[] unable to pick up command line arguments <niall.macpherson@ntlworld.com>
Re: ARGV[] unable to pick up command line arguments <jurgenex@hotmail.com>
Re: ARGV[] unable to pick up command line arguments <1usa@llenroc.ude.invalid>
Re: ARGV[] unable to pick up command line arguments <vk4tec@people.net.au>
Re: ARGV[] unable to pick up command line arguments <jurgenex@hotmail.com>
Re: ARGV[] unable to pick up command line arguments <niall.macpherson@ntlworld.com>
Assigning virtual filename to eval block tobias.grimm@cas-soft.de
Re: Assigning virtual filename to eval block <joost@zeekat.nl>
Re: Assigning virtual filename to eval block <ben@morrow.me.uk>
Re: Assigning virtual filename to eval block <1usa@llenroc.ude.invalid>
Re: Assigning virtual filename to eval block <1usa@llenroc.ude.invalid>
Re: Assigning virtual filename to eval block tobias.grimm@cas-soft.de
Re: Assigning virtual filename to eval block tobias.grimm@cas-soft.de
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 19 May 2008 04:16:19 -0700 (PDT)
From: Niall Macpherson <niall.macpherson@ntlworld.com>
Subject: ARGV[] unable to pick up command line arguments
Message-Id: <39f6e7b4-c083-4203-bbcb-9f49369f06f6@w7g2000hsa.googlegroups.com>
I've recently returned to using perl after a year or so away.
I inherited a script which was using Getopt::Std but when I ran it I
couldn't seem to pick up the command line args correctly. I looked at
ARGV[] and this was showing empty.
I therefore just tried running the following
use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";
No matter what I pass on the command line, single quoted , double
quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].
U:\PerlScripts>argv.pl "aaaaa" "ddddd"
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg0=
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg1=
The only command I can get to work is as follows
U:\PerlScripts>perl -le "print $ARGV[0]" "dddddddddd"
dddddddddd
U:\PerlScripts>
Having been away from perl for some time I guess I'm missing something
fundamental here. Perl is ActiveState 5.8.3
------------------------------
Date: Mon, 19 May 2008 11:45:05 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: ARGV[] unable to pick up command line arguments
Message-Id: <5jp234tsidhg2m37n2it19knppc9iqqs6q@4ax.com>
Niall Macpherson <niall.macpherson@ntlworld.com> wrote:
>use strict;
>use warnings;
>print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";
>
>No matter what I pass on the command line, single quoted , double
>quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].
Check if the command line arguments are being passed to the application
in the file extension bindings:
In Explorer go to 'Tools' -> 'Folder Options' -> 'File Types'.
Select 'PL file' -> click 'Advanced' -> select 'Open' -> click 'Edit' ->
check 'Application used to perform action'. The value should end with
the parameter list:
[pathToPerlInterpreter]\perl.exe" "%1" %*
jue
------------------------------
Date: Mon, 19 May 2008 11:50:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: ARGV[] unable to pick up command line arguments
Message-Id: <Xns9AA34FD50E926asu1cornelledu@127.0.0.1>
Niall Macpherson <niall.macpherson@ntlworld.com> wrote in news:39f6e7b4-
c083-4203-bbcb-9f49369f06f6@w7g2000hsa.googlegroups.com:
> I've recently returned to using perl after a year or so away.
s/perl/Perl/
> I therefore just tried running the following
>
> use strict;
> use warnings;
> print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";
>
> No matter what I pass on the command line, single quoted , double
> quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].
>
> U:\PerlScripts>argv.pl "aaaaa" "ddddd"
> Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
> arg0=
> Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
> arg1=
>
> The only command I can get to work is as follows
>
> U:\PerlScripts>perl -le "print $ARGV[0]" "dddddddddd"
> dddddddddd
>
> U:\PerlScripts>
>
> Having been away from perl for some time I guess I'm missing something
> fundamental here. Perl is ActiveState 5.8.3
Most likely, this has nothing to do with Perl but with the fact that the
file association for .pl is not correctly set up (in the Windows
registry).
Make sure the following match the output of the same commands on your
system.
E:\> assoc .pl
.pl=Perl
E:\> ftype Perl
Perl="C:\opt\Perl\bin\perl.exe" "%1" %*
My guess is that on your system, the trailing %* will be missing. You
should be able to fix that. You can get help on the ftype command by
typing
E:\> ftype /?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Mon, 19 May 2008 22:03:03 +1000
From: "Andrew Rich" <vk4tec@people.net.au>
Subject: Re: ARGV[] unable to pick up command line arguments
Message-Id: <48316c7a$1_5@news.peopletelecom.com.au>
Take another stab in the dark
#!/usr/bin/perl
use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";
./args.pl andy barry
arg0=andy
arg1=barry
Where you missing the command interpreter ? in line 1
"Niall Macpherson" <niall.macpherson@ntlworld.com> wrote in message
news:39f6e7b4-c083-4203-bbcb-9f49369f06f6@w7g2000hsa.googlegroups.com...
> I've recently returned to using perl after a year or so away.
>
> I inherited a script which was using Getopt::Std but when I ran it I
> couldn't seem to pick up the command line args correctly. I looked at
> ARGV[] and this was showing empty.
>
> I therefore just tried running the following
>
> use strict;
> use warnings;
> print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";
>
> No matter what I pass on the command line, single quoted , double
> quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].
>
> U:\PerlScripts>argv.pl "aaaaa" "ddddd"
> Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
> arg0=
> Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
> arg1=
>
> The only command I can get to work is as follows
>
> U:\PerlScripts>perl -le "print $ARGV[0]" "dddddddddd"
> dddddddddd
>
> U:\PerlScripts>
>
> Having been away from perl for some time I guess I'm missing something
> fundamental here. Perl is ActiveState 5.8.3
>
>
------------------------------
Date: Mon, 19 May 2008 12:12:41 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: ARGV[] unable to pick up command line arguments
Message-Id: <0fr234tetm30b2tf2rtdto3k1l6kce27he@4ax.com>
[Please no TOFU, trying to repair]
"Andrew Rich" <vk4tec@people.net.au> wrote:
>"Niall Macpherson" <niall.macpherson@ntlworld.com> wrote in message
>> No matter what I pass on the command line, single quoted , double
>> quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].
>>
>> U:\PerlScripts>argv.pl "aaaaa" "ddddd"
>> [...]
>Take another stab in the dark
>#!/usr/bin/perl
>use strict;
[...]
>Where you missing the command interpreter ? in line 1
As evidenced by the command prompt
U:\....
the OP is using Windows. Therefore the shebang line will happily be
ignored.
jue
------------------------------
Date: Mon, 19 May 2008 06:05:37 -0700 (PDT)
From: Niall Macpherson <niall.macpherson@ntlworld.com>
Subject: Re: ARGV[] unable to pick up command line arguments
Message-Id: <a4037ee7-3f8f-4ade-889a-2458544686e0@c58g2000hsc.googlegroups.com>
Many thanks jue and Sinan
The trailing %* was missing and adding it has fixed the problem
>
> In Explorer go to 'Tools' -> 'Folder Options' -> 'File Types'.
> Select 'PL file' -> click 'Advanced' -> select 'Open' -> click 'Edit' ->
> check =A0'Application used to perform action'. The value should end with
> the parameter list:
>
> =A0 =A0 =A0 =A0 [pathToPerlInterpreter]\perl.exe" "%1" %*
>
> jue
------------------------------
Date: Mon, 19 May 2008 05:05:12 -0700 (PDT)
From: tobias.grimm@cas-soft.de
Subject: Assigning virtual filename to eval block
Message-Id: <4278b13b-e111-441e-8607-73e79ac2233d@m36g2000hse.googlegroups.com>
Hi!
Assuming I have something like this:
my $str = "sub foo { print 1 / 0; }";
eval($str);
foo();
... then I get:
Illegal division by zero at (eval 1) line 1.
Can I somehow give the eval block a more meaningful filename than
"(eval N)"?
Tobias
------------------------------
Date: Mon, 19 May 2008 14:28:46 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: Assigning virtual filename to eval block
Message-Id: <87lk26tr41.fsf@zeekat.nl>
tobias.grimm@cas-soft.de writes:
> Hi!
>
> Assuming I have something like this:
>
> my $str = "sub foo { print 1 / 0; }";
> eval($str);
> foo();
>
> ... then I get:
>
> Illegal division by zero at (eval 1) line 1.
>
> Can I somehow give the eval block a more meaningful filename than
> "(eval N)"?
>
my $str = <<CODE;
#line 1 /my/fake/file.txt
sub foo { print 1 / 0; }
CODE
See also the end of perlsyn.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Mon, 19 May 2008 13:31:23 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Assigning virtual filename to eval block
Message-Id: <rh88g5-cj3.ln1@osiris.mauzo.dyndns.org>
Quoth tobias.grimm@cas-soft.de:
>
> Assuming I have something like this:
>
> my $str = "sub foo { print 1 / 0; }";
> eval($str);
> foo();
>
> ... then I get:
>
> Illegal division by zero at (eval 1) line 1.
>
> Can I somehow give the eval block a more meaningful filename than
> "(eval N)"?
Use #line:
my $str = <<'PERL'
#line 1 eval_for_foo
sub foo { print 1/0 }
PERL
eval $str or die $@;
foo();
(at least in my version of perl it's necessary to check the eval
succeeded, as otherwise the division is done at compile time, as part of
constant folding, and the sub never gets created at all).
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Mon, 19 May 2008 12:43:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Assigning virtual filename to eval block
Message-Id: <Xns9AA358B48BF4Dasu1cornelledu@127.0.0.1>
tobias.grimm@cas-soft.de wrote in news:4278b13b-e111-441e-8607-
73e79ac2233d@m36g2000hse.googlegroups.com:
> Assuming I have something like this:
I would to have to first ask why you are using a string eval for what is
just an anonymous sub invocation. You might have a good reason, but most
posters don't, so I ask.
Now, given that you are calling foo by name after the eval, I really
cannot think of any reason to use a string eval rather than an anonymous
subroutine.
> my $str = "sub foo { print 1 / 0; }";
> eval($str);
> foo();
Compare it to
my $sub = sub { print 1/0 };
$sub->();
> ... then I get:
>
> Illegal division by zero at (eval 1) line 1.
>
> Can I somehow give the eval block a more meaningful filename than
> "(eval N)"?
I don't know. Frankly, I don't think you should waste time on this.
If you use an anonymous sub you will get both compile time error
checking and the ability to apply hack #57 in the excellent "Perl
Hacks" book.
The code is available at <URL:http://examples.oreilly.com/perlhks/>.
Download the archive at that location and look in
perl_hacks_examples\debugging\name_your_anonymous_subroutines
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Mon, 19 May 2008 12:47:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Assigning virtual filename to eval block
Message-Id: <Xns9AA3595DACDD6asu1cornelledu@127.0.0.1>
Ben Morrow <ben@morrow.me.uk> wrote in news:rh88g5-cj3.ln1
@osiris.mauzo.dyndns.org:
> Quoth tobias.grimm@cas-soft.de:
>>
>> Assuming I have something like this:
>>
>> my $str = "sub foo { print 1 / 0; }";
>> eval($str);
>> foo();
>>
>> ... then I get:
>>
>> Illegal division by zero at (eval 1) line 1.
>>
>> Can I somehow give the eval block a more meaningful filename than
>> "(eval N)"?
>
> Use #line:
>
> my $str = <<'PERL'
> #line 1 eval_for_foo
> sub foo { print 1/0 }
> PERL
>
> eval $str or die $@;
> foo();
Well, that's clever. I am afraid I forgot about #line as I have never
had a reason to use it.
On the other hand, am I the only one who thinks it smells bad to use
string eval for a function invoked by name?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Mon, 19 May 2008 05:48:21 -0700 (PDT)
From: tobias.grimm@cas-soft.de
Subject: Re: Assigning virtual filename to eval block
Message-Id: <792175d1-a5b5-49b9-8906-b5795411a2b1@m45g2000hsb.googlegroups.com>
Jost, Ben - Thanks a lot! That was just too easy :-)
Tobias
------------------------------
Date: Mon, 19 May 2008 05:58:39 -0700 (PDT)
From: tobias.grimm@cas-soft.de
Subject: Re: Assigning virtual filename to eval block
Message-Id: <3f7209a1-8a50-4c4d-84e0-e8266c2f8315@k13g2000hse.googlegroups.com>
Sinan,
this was just as small sample. I have a perl module written in C++
which generates perl module code at runtime and evals it, so it
becomes available to the calling perl application.
Tobias
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1555
***************************************