help logoLON-CAPA Help

Courses in a domain can be self-cataloging if assigned an institutional code. For this to work two routines need to be customized in - instcode_format() and instcode_defaults(). The first of these is used to split institutional course codes into their constituent parts, and populate some perl data structures with these data, which LON-CAPA can use to generate linked select boxes which users can use to create filters to apply when searching the "official" course catalog. The second routine constructs a regular expression used when searching for courses based on the filter chosen by the user, which will contain fragments of an institutional code.


Six arguments are required:

  1. domain ($dom)

  2. reference to hash of institutional course IDs ($instcodes)

  3. reference to hash of codes ($codes)

  4. reference to array of titles ($codetitles),
    e.g., @{$codetitles}
    = ("year","semester","department","number")

  5. reference to hash of abbreviations used in categories, ($cat_titles) e.g.,

    %{$$cat_titles{'Semester'}} = (
    fs = > 'Fall',

    ss = > 'Spring',

    us = > 'Summer');

  6. reference to hash of arrays specifying sort order used in category titles ($cat_order), e.g., @{$$cat_order{'Semester'}} = ('ss','us','fs');

The routine returns 'ok' if no errors occurred.

At MSU, "fs13nop590" is an example of an institutional course code; including the following entry in the instcodes hash passed in by reference - $$instcodes{'43551dedcd43febmsul1'} = 'fs13nop590' would cause the $codes perl data structure to be populated.

fs13nop590 would be split as follows:

$$codes{{'year'} = '2013'

$$codes{'semester'} = 'Fall'

$$codes{'department'} = 'nop'

$$codes{'number'} = '590'

The routine used at MSU is as follows:

sub instcode_format {
my ($dom,$instcodes,$codes,$codetitles,$cat_titles,$cat_order) = @_;

@{$codetitles} = ("Year","Semester","Department","Number");

%{$$cat_titles{'Semester'}} = (

fs => 'Fall',

ss => 'Spring',

us => 'Summer'


@{$$cat_order{'Semester'}} = ('ss','us','fs');

foreach my $cid (keys %{$instcodes}) {

if ($$instcodes{$cid} =~ m/^([suf]s)(\d{2})(\w{2,3})(\d{3,4}\w?)$/) {
$$codes{$cid}{'Semester'} = $1;

$$codes{$cid}{'Department'} = $3;

$$codes{$cid}{'Number'} = $4;

my $year = $2;

my $numyear = $year;

$numyear =~ s/^0//;

$$codes{$cid}{'Year'} = $year;

unless (defined($$cat_titles{'Year'}{$year})) {

$$cat_titles{'Year'}{$year} = 2000 + $numyear;

my $outcome = 'ok';

return $outcome;


Three arguments are required:

  1. domain ($dom)

  2. reference to hash which will contain default regular expression matches for different components of an institutional course code


  3. reference to array which will contain order of component parts used in institutional code. ($code_order)

The routine returns 'ok' if no errors occurred.

At MSU, the regular expression fragments used mirror those included in the regular expression used in instcode_format() to split an institutional course code into its component parts.

sub instcode_defaults {
my ($dom,$defaults,$code_order) = @_;

%{$defaults} = (

'Year' => '\d{2}',

'Semester' => '^[sfu]s',

'Department' => '\w{2,3}',

'Number' => '\d{3,4}\w?',


@{$code_order} = ('Semester','Year','Department','Number');

return 'ok';