Perl Import Filter

Perl based import filter can be very useful to import files with unusual data format. Plot builds an easy to access framework arround your script which allow to pass the data to Plot. Errors produced by the script will be shown in the console of the Macro Inspector.

To create a Perl import filter open the Macro Inspector choose Add in the panel an select Perl Import as type. In the large text field of the Macro Inspector you can now enter your script.

Predefinitions

The following variables and subroutines are available in your Perl import filter:

$file

The filename of the file you want to import.

&log()

Send output to the console in the Macro Inspector.

@data[buffer][point number][column]

A three dimensional array which should contain the data at the end of your script.
[buffer]: The number of the buffer (starting with 0)
[point number]: The number of the data point (starting with 0)
[column]: The column number (0 = X value, 1 = Y value, 2 = X error, 3 = Y error)

@commnet[buffer]

In this array you can set comments for each imported buffer (visible in the Data Inspector).

@source[buffer]

In this array you can set source information for each imported buffer (visible in the Data Inspector).

%var{key}

If the script is started from a macro this hash contains all number variables. The variables will also be returned to the macro.

%svar{key}

If the script is started from a macro this hash contains all string varibles. The variables will also be returned to the macro.

Restrictions

  • Do not send anything to STDERR and STDOUT.
  • Do not use any interactive things.
  • If your Perl script hangs Plot will hang too (sorry, this has to be changed in the future). You can kill a hanging Perl script from the Terminal.app

Example

The following example demonstrates how to import a file containing two columns separated by <Tab>. The script also checks for the correct number of columns and sets the buffer comment.

 open(IN,$file);
 $n=0;
 while(<IN>) {
   @tmp=split('\t');
   if ($#tmp==1) {
     $data[0][$n][0]=$tmp[0];
     $data[0][$n][1]=$tmp[1];
     $n++	
   }
 }
 close(IN);
 $comment[0]='Test';
 &log("$n number of points");