<div dir="ltr">
Hello, <br><br>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: <div>sub { my ( $data ) = @_;<br> my $record;<br> foreach my $key (keys %$data) {<div> $record->{ $data->{$key } } = $key;<br> }<br> return $record;<br>}<br><br></div><div>and I used it with the following command: catmandu convert CSV --file csv2unimarc_test.csv --fix 'perlcode(<a href="http://01_test.pl">01_test.pl</a>)' to JSON --pretty 1<br></div><div><br>Unfortunately, the data were not modified. So, I’ve changed the code as follows: sub {</div><div> my ( $data ) = @_;<br> foreach my $key (keys %$data) {</div><div> $data->{ $data->{$key } } = $key;<br> delete $data->{$key};<br> }<br> return $data;<br>}<br><br>And used the same command. In this case, the data were modified. <br><br>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: <br>sub {</div><div> my ( $data ) = @_;<br> foreach my $key (keys %$data) {</div><div> $data->{ $data->{$key } } = $key;<br> delete $data->{$key};<br> }<br> return 3; # <- return a constant</div><div>}<br><br>And so, I understood that the returned value is apparently not used by Catmandu. And the first argument is in fact a reference. <br><br>I guess it’s a feature and not a bug, but can anybody confirm it is the right behavior?<br><br>And is it not something worth mentioning in the documentation?<br><br>Thanks in advance,<br><br>Emmanuel Di Pretoro</div></div></div>