# Perl Data Filter

Perl based data filter passes all selected buffers to a Perl script where the data can be manipulated. When the script has finished the data will be returned to Plot as new data buffers. Plot builds an easy to access framework around your script which allow to pass the data to Plot. Errors produced by the script will be shown in the console of the inspector.

To create a Perl data filter open the macro editor, choose Add in the panel, and select Perl Filter as type. In the large text field of the macro editor you can now enter your script.

## Predefinitions

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

`&log()`

Send output to the console in the macro editor.

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

A three dimensional array which contains the data of all selected buffers at the beginning of the script. At the end of the script the array will be returned to Plot
`[buffer]`: The number of the buffer (starting with 0)
`[point number]`: The number of the data points (starting with 0)
`[column]`: The column number (0 = X value, 1 = Y value, 2 = X error, 3 = Y error)

`@commnet[buffer]`

This array you contain the comments of your buffers.

`@source[buffer]`

This array you contain the source information of your buffers

`$nb`

The number of buffers passed to the script.

`%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 variables. The variables will also be returned to the macro.

## Restrictions

- Do not send anything to STDERR and STDOUT.
- Do not use any interactive things.

## Example

The following example demonstrates how to apply manipulations to your buffers (in this case 1.23 will be added to the Y values and a string will be appended to the comment field).

     for ($j=0;$j<$nb;$j++) {
       $np=$#{$data[$j]}+1;
       $nc=$#{$data[$j][0]}+1;
       for ($i=0;$i<$np;$i++) {
         $data[$j][$i][1]+=1.23;
       }
       $comment[$j].=" added 1.23";
     }