From hart at physics.arizona.edu Tue Mar 4 17:55:32 2003 From: hart at physics.arizona.edu (Sam Hart) Date: Wed Aug 4 00:10:51 2004 Subject: TPM: Perl execution method question Message-ID: (I'm not sure if this list is used much for anything, there's no archive as far as I can tell, so excuse me asking this on this list if that's not what the list is for... also, I just subscribed, so I have no backhistory to reference ;-) I am writing a script which will have a variety of calling methods dependant on its usage (as a mail wrapper, CGI script, and even from the command line) and I can't seem to find a way to tell the scripts execution method (without just checking for %ENV values that may or may not be portable). Anyone know of a way to tell in Perl how a perl script was ran? -- Sam Hart University/Work addr. Personal addr. end From hart at physics.arizona.edu Tue Mar 4 18:40:24 2003 From: hart at physics.arizona.edu (Sam Hart) Date: Wed Aug 4 00:10:51 2004 Subject: TPM: Perl execution method question In-Reply-To: Message-ID: > Out of curiousity, why do you need a single script to do all of this? > Wouldn't it be easier to make several? If there is a lot of common code > you could put it in another file and require it from the seperate files. Because I haven't yet decided what final interfaces I want for the script, so I really don't want to lock anything down just yet. Plus, it will make it easier to install and set-up. (In case you're curious, I've got a little news/blogging script I've used for a while over at tux4kids, and I'm trying to make it easier for our developers to submit messages to it... ie they can use the web if desired, or CC this script their general news announcements they already email, etc. By doing this, then I don't have the be the PR person in addition to all my other duties ;-) > One could also make aliases/links of the same file to different names and > then check to see the invoked name of the script. $0 or something of > that nature... > > For example: > ---------------------------------------------- > % touch actual_script.pl > % ln -s actual_script.pl cgi-version > % ln -s actual_script.pl mail-version > % vi actual_script.pl > #!/usr/bin/perl > > if( $0 eq 'cgi-version' ) { > > # do cgi-stuff here... > > } elsif( $0 eq 'mail-version' ) { > > # do mail stuff here > > } else { > > # Do debugging or error stuff here > > } > ---------------------------------------------- > > Hope this helps, Actually, yes, this does. This would work perfectly plus it would allow for addition of new interfaces as needed. Dunno why I didn't think of that... Guess it's one of those forest for the trees kind of things ;-) -- Sam Hart University/Work addr. Personal addr. end