Personal tools
You are here: Home cmgui Wiki CMISS Perl Interpreter Quirks
Views

CMISS Perl Interpreter Quirks

last edited 3 years ago by blackett

Don't be fooled into thinking that you can program ordinary Perl in comfiles. There are several important differences arising because of the necessity to allow interactive input.

Add any quirks you notice here.

  • Due to backwards compatibility with old CMISS commands the Perl Interpreter does not have a line delimiter character, semicolons are not required on the end of lines. Instead you cannot continue any command from one line to the next which is a real pain when initialising hashes. The following does not work even though it is legitimate perl:
        {
          my %fred = {bob => 'happy',
                      rachel => 'excited',
                      fred => 'sad'};
        }
    

Instead you have to write it all on one line:

    {
      my %fred = {bob => 'happy', rachel => 'excited', fred => 'sad'};
    }

  • Variables declared with my only apply within the current scope. When you type code interactively then each line exists as a single entity (and therefore any my variables will not exist as soon as that line returns). Therefore when you are working interactively do not use my. However in your comfiles the best way to make things work properly is to use braces to correctly define the scope you want. This has the added advantage of having the whole file compile in a single call to perl and is therefore faster:
       {
         use strict;
    
         my $bob;
         my @fred = ("fred1", "fred2", "fred3");
    
         $bob = $fred[1];
         print "$bob $fred[2]\n";
       }
    
  • Post declared if ie $x=1 if defined $foo; doesn't work. Use if(defined $foo){$x=1} instead.

Contributing to this site

Please add to the wiki any relevant information that you think might be useful to other users of this website. For example, you might like to contribute your experiences, questions and answers.

You are encouraged to contribute to this site regardless of your level of experience. Contributions are welcomed from new and regular visitors.

If you ask a question and receive an answer from a developer you should record it in the wiki. This information is extremely useful and can help other users overcome the same problem.

See how to add and edit pages for more information.