Robert Spier on Sun, 16 Apr 2000 20:45:38 -0400 (EDT) |
>>>>> "JK" == John Kirk <dystan@pac.net> writes: JK> I think I got all that. I believe the most immediate difficulty JK> for me is the behavior of the exec() function, when called the way JK> I was doing it. Doesn't look to me as if it's doing what the JK> camel book said. I guess you're right, though. I do entertain JK> the expectation you describe. I haven't seen precisely how JK> they're different, in any perl documentation. Do you know where I JK> should look for more detailed specification of perl's JK> implementation of this? perldoc -f exec that's the "definitive" documentation (second to the source code that is.) JK> This is just like my tst00, leaving off the copy of the file JK> contents. It shows "... is tst04" if the procedure I cited for JK> tst04 is followed, i.e. making tst04 a soft link to the script and JK> invoking tst04 at the command line. Perl doesn't know that it's a softlink, so "name of the current script" would be tst04. >> --- t2.pl --- #!/usr/bin/perl exec './t1.pl' '-george'; JK> This is just like my tst02, and I read the camel book passage I JK> cited as saying it should execute ./t1.pl, but make it think it JK> was invoked as -george instead. This is the behavior comparable JK> to the soft link way of invoking it, no? (As in, accessing the JK> same implementation behind the scenes) No. The softlink is a transparent way of also accessing the on disk file with a different name. so.. under the covers, when the OS's loader goes to load the 'binary' it looks up the inode for tst04, see's its a symlink to tst01, and then looks up the inode of tst01. It still _thinks_ it's tst04 though. when using exec in the second example (With george), it loads up the binary image for tst01, sets argv[0] to '-george' and runs it. >> --- t3.pl --- #!/usr/bin/perl exec './argv0' '-george'; --- argv0.c >> --- #include <stdio.h> int main(int argc,char **argv) { >> printf("argv[0] = %s\n",argv[0]); } JK> This gives the behavior I expect. Do we know exactly what the JK> differences are between $0 in perl and argv[0] in C? I had the JK> impression that they were both accessing the same info from the JK> OS. Yes. They are similar and unrelated. argv[0] is the name by which the program was invoked (from K&R). $0 Contains the name of the file containing the Perl script being executed. On some operating systems assigning to "$0" modifies the argument area that the ps(1) program sees. This is more useful as a way of indicating the current program state than it is for hiding the program you're running. (Mnemonic: same as sh and ksh.) see the difference? $0 contains the name of the file being executed. That's different from 'the name by which the program was invoked' JK> That's what my empirical observations indicate. My problem is JK> that I understood the documentation of perl and the features JK> provided by the implementation of *nix to indicate that this kind JK> of thing is available. it is. But not in Perl the way you want it. >> Maybe what you want can be achived with C< do >? JK> I don't know what you're suggesting, here. Could you elaborate JK> on the idea. --- perldoc -f do --- Uses the value of EXPR as a filename and executes the contents of the file as a Perl script. Its primary use is to include subroutines from a Perl subroutine library. do 'stat.pl'; is just like scalar eval `cat stat.pl`; --- --- T5.pl -- #!/usr/bin/perl do 'T6.pl'; T6.pl -- #!/usr/bin/perl print "I am $0\n"; $ perl T5.pl I am T5.pl -R **Majordomo list services provided by PANIX <URL:http://www.panix.com>** **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|