[librecat-dev] Questions about the behavior of perlcode in Fix
Emmanuel Di Pretoro
edipretoro at gmail.com
Mon Apr 4 14:32:29 CEST 2016
Hello,
I’m quite new with Catmandu and I’m still exploring its features. I’m
currently playing with perlcode. And I have some questions about it. In my
first try to use it, I’ve written the following code:
sub { my ( $data ) = @_;
my $record;
foreach my $key (keys %$data) {
$record->{ $data->{$key } } = $key;
}
return $record;
}
and I used it with the following command: catmandu convert CSV --file
csv2unimarc_test.csv --fix 'perlcode(01_test.pl)' to JSON --pretty 1
Unfortunately, the data were not modified. So, I’ve changed the code as
follows: sub {
my ( $data ) = @_;
foreach my $key (keys %$data) {
$data->{ $data->{$key } } = $key;
delete $data->{$key};
}
return $data;
}
And used the same command. In this case, the data were modified.
I thought at first it was the behavior of the function 'do()' used
internally in Catmandu::Fix::perlcode. But after a quick test, I know this
is not. So I’ve tried some variations, one of them was:
sub {
my ( $data ) = @_;
foreach my $key (keys %$data) {
$data->{ $data->{$key } } = $key;
delete $data->{$key};
}
return 3; # <- return a constant
}
And so, I understood that the returned value is apparently not used by
Catmandu. And the first argument is in fact a reference.
I guess it’s a feature and not a bug, but can anybody confirm it is the
right behavior?
And is it not something worth mentioning in the documentation?
Thanks in advance,
Emmanuel Di Pretoro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-bielefeld.de/mailman2/unibi/public/librecat-dev/attachments/20160404/d85cdb10/attachment.html>
More information about the librecat-dev
mailing list