Gossamer Forum
Home : Products : DBMan : Customization :

Sub routine question

Quote Reply
Sub routine question
Hi

I am writing a few mods for my dbman script, but I would like to place them in a seperate file. I have defined this file in the cfg file, as a require file.

The mods involve several different sub routines, for different functions. I require to take the input data from

%rec

I know they work as I have tested them built directly into the htmp.pl file, but I am having difficulty calling them from the file that I made up.

I thought I could define the scalar output in the sub routine in html.pl by using

my $modoutput;

and then inserting

&call_my_subroutine;

and placing

$modoutput where I wanted the output

This will not work.

What am I missing?

Oh yes I am reasonably new to perl, reading books, but its great, well worth trying to anybody thinking about it.

Thanks


DavyC
http://www.amijet.com
Life's more fun in a virtual world
Quote Reply
Re: Sub routine question In reply to
In the sub routine where the output is to be shown add....

my $VARIABLENAME = shift;

Then put $VARIABLENAME where you want to show the value.

I think that is what you mean?....

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Sub routine question In reply to
Hi Paul

Thanks, much appreciated, will try that.

Many thanks

DavyC
http://www.amijet.com
Life's more fun in a virtual world
Quote Reply
Re: Sub routine question In reply to
Hi

No - sorry, working on a virtual airline site,

the database is for a pilots record

there are two functions

1. calculate total hours taken from 6 seperate fields, the total hours only needs to be displayed not kept in database here is the sub a used


sub total_hours {
#------------------------------------------------------------
my (%rec) = @_;
my $total_hours;

$total_hours = ($rec{'Cat A Hours'} + $rec{'Cat B Hours'} + $rec{'Cat C Hours'}
+ $rec{'Cat D Hours'} + $rec{'Cat E Hours'} + $rec{'Previous VA Hours'});
}


giving me output of $total_hours, I would like to keep this and the next sub in a seperate file I called pilots.mod,

but how do I call the sub I know

&total_hours;

but where do I place this, I have tried several different places (I use short long display and only want it in the long display).

The second function is similar however takes the hours and gives a rank started the sub, gives you an idea

sub Cat_a_rank {
#-------------------------------------------------------------
my (%rec) = @_;
my $cat_a_rank;

if ($rec{'Cat A Hours'} < 20) {
$cat_a_rank = "Pilot";
}
elsif{
$rec{'Cat A Hours'} <50
$cat_a_rank = "Snr 1st Officer";

I know still working on it, there will be numerous subs similar to chis for different categories, and one which needs to divide hours etc. but in the above example where I have used 20 I would like to replace with a scalar which will be defined in the .cfg in order that I can change easily at a later date.

In brief, where do I place

&sub_routine;

and can I place them in a sperate file called pilots.mod or something like this, I did not include a shebang line, as I thought you didn't need to in sub files like this.

Thanks

DavyC
http://www.amijet.com
Life's more fun in a virtual world
Quote Reply
Re: Sub routine question In reply to
phew I read that post twice and barely understood both times Smile

At the top of html.pl add.....

require "pilots.pl"; # Give it a .pl ending to keep it neat

Then you can just call the sub wherever you want.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/