Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:
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.


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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho