---
name: "Catmandu::Fix::perlcode"
section: "3pm"
platform: "linux"
package: "libcatmandu-perl"
version: "1.2024-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Catmandu::Fix::perlcode"
---

# Catmandu::Fix::perlcode(3pm)

execute Perl code as fix function

## NAME

Catmandu::Fix::perlcode - execute Perl code as fix function

## DESCRIPTION

Use this fix in the Catmandu fix language to make use of a Perl script:

```
    perlcode(myscript.pl)
```

The script (here `"myscript.pl"`) must return a code reference:

```
    sub {
        my $data = shift;
        $data->{testing} = 1 ; # modify the item
        return $data;          # and return the data
    }
```

When not using the fix language this

```
    my $fixer = Catmandu::Fix->new( fixes => [ do 'myscript.pl' ] );
    $fixer->fix( $item );
```

is roughly equivalent to:

```
    my $code = do 'myscript.pl';
    $item = $code->( $item )
```

All scripts are cached based on their filename, so using this fix multiple times will only load each given script once.

The code reference gets passed a second value to reject selected items such as possible with see Catmandu::Fix::reject:

```
    sub {
        my ($data, $reject) = @_;
        if ($data->{my_field} eq 'OK') {
            return $data;    # return the data and continue processing
        }
        else {
            return $reject;  # return the reject flag to ignore this record
        }
    }
```

## SEE ALSO

Catmandu::Fix::code, Catmandu::Fix::cmd
