2.4. Last Newline

The last line in a Scilab script is ignored if it is not terminated by a newline.[1] This is emphasized at several places in the official Scilab documentation, but it is so common to forget it especially when using emacs that we repeat it here. emacs however can be told always to add a final newline by adding (setq require-final-newline t) to the startup-file, .emacs. See "Learning GNU Emacs" [Cameron:1996] , Table C-8.

Another weapon against this kind of syntax flaw, and a few other pesky things, is e.g. the Perl-script shown in Example 2-2, which fixes part of the format of a Scilab script.

Example 2-2. Canonicalization of Scilab files


use Text::Tabs;

while (<>) {
    chomp;                  # remove newline if there is one
    tr/\200-\377/ /;        # map 8-bit chars to spaces
    s[\s+$][];              # kill whitespace at end of line 
    $_ = expand $_;         # convert tabs to spaces
    print "$_\n";           # print adding a newline
}
   

Notes

[1]

On UNI* systems the line terminator is ^J, which is writtan in C-style \n most of the time.