| |||||||||||
| |||||||||||
converting from c-shell Posted by kejones (kejones), 9 November 2004 I am converting some old c-shell scripts to perl. Most of the scripts 'source' another c-shell file that contains the definitions for numerous constants.For example:- set aux_file = off set notify = on etc, etc What is the best way to transfer this to perl - both the file of constants and getting the new scripts to load those constants? Thanks Posted by admin (Graham Ellis), 9 November 2004 What are you using the variables for? If you're currently using them within your Shell script and you're going to be using them in the future in the Perl equivalent, then you'll want to use an assignment such as $aux_file = "off"; $notify = "on"; On the other hand, if you're going to be using them in shell commands that you call from your perl, you'll want to set them in you environment, for example $ENV{"aux_file"} = "off"; $ENV{"notify"} = "on"; If you would care to post a bit further about what you're going to do with the varaibles once they're set, I'll expand on the relevant parts of my answer. Posted by kejones (kejones), 9 November 2004 They are to be used as option 1 - the perl scripts are being written to replace the shell scripts. So, a new perl file will be created to hold the variables and the replacement scripts will need to load that file to get the variables.Posted by admin (Graham Ellis), 10 November 2004 on 11/09/04 at 17:32:33, kejones wrote:
OK ... then you'll want to place Perl commands like the ones I started with (simple assignments) into the file to be included in your main scripts, and you'll need to add a line 1; at the end of that file You can EITHER give the file an extension .pm (e.g. call it fred.pm) and bring it in using: use fred; note the lack of quotes and the lack of .pm in the command OR you can give it any extension you wish (say call it dibble.inc) and bring it in with t require statement: require "dibble.inc"; The difference is that use is brought in at compile time, whereas require is brought in at run time. Conventional wisdom is that use is usually best but if (for example) you have the user enter the name of the file of parameters, you'll need to choose require. Posted by kejones (kejones), 10 November 2004 It all works wonderfully!Thankyou. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |