Re: How to pass a ref from a language with no refs
* Mark Stosberg [EMAIL PROTECTED] [2006-09-29 14:18]: my $p5_dumper = eval('sub {use Data::Dumper; print Dumper(@_); }', :langperl5); my @a = b c d; $p5_dumper.(@a); # received as array $p5_dumper.([EMAIL PROTECTED]); # received as arrayref $p5_dumper.(VAR @a); # received as arrayref my %h = ( a = 1 ); $p5_dumper.(@%h); # received as hashref $p5_dumper.([,] %h); # received as hashref $p5_dumper.(|%h); # received as hashref $p5_dumper.(%h); # received as hashref $p5_dumper.(\%h); # received as hashref $p5_dumper.(VAR %h); # received as hashref I think you want $p5_dumper.(%h.kv); Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/
Re: How to pass a ref from a language with no refs
Mark Stosberg wrote: When Perl 5 has references and Perl 6 doesn't, I don't know what to expect to when I need to pass a hash reference to a Perl 5 routine. Such details make no appearance currently in the Perl 6 spec, but I'm trying to gather them on the wiki if you have anything to add: http://rakudo.org/perl6/index.cgi?using_perl_5_embedding I saw there have been some commits lately to Perl5 embedding, so I tried some experiments with pugs to figure out if I could determine reliable ways pass hashes and arrays to Perl5, so that they are received as hashes, hashrefs, arrays, or arrayrefs, as appropriate. I came up with the following test. As you can see, with arrays I was able to pass them as a reference or not. However, when attempting to pass a hash, it always came through as a hash, never flattened. Have I missed something? my $p5_dumper = eval('sub {use Data::Dumper; print Dumper(@_); }', :langperl5); my @a = b c d; $p5_dumper.(@a); # received as array $p5_dumper.([EMAIL PROTECTED]); # received as arrayref $p5_dumper.(VAR @a); # received as arrayref my %h = ( a = 1 ); $p5_dumper.(@%h); # received as hashref $p5_dumper.([,] %h); # received as hashref $p5_dumper.(|%h); # received as hashref $p5_dumper.(%h); # received as hashref $p5_dumper.(\%h); # received as hashref $p5_dumper.(VAR %h); # received as hashref
Re: How to pass a ref from a language with no refs (was: Re: use perl5:CGI as a solution)
Mark Stosberg skribis 2006-09-17 8:10 (-0500): Please note that eventually, perl5:CGI is supposed to work as expected. For that to happen, there will first have be some documentation telling me what expectations to have. Good point, but I think your expectations are natural and logical. When Perl 5 has references and Perl 6 doesn't, I don't know what to expect to when I need to pass a hash reference to a Perl 5 routine. That's mostly terminology. I expect that the syntax will still be the same. That is: perl5sub( { ... } ); # Anonymous hash perl5sub( \%hash );# Capture of a real hash Such details make no appearance currently in the Perl 6 spec, but I'm trying to gather them on the wiki if you have anything to add: http://rakudo.org/perl6/index.cgi?using_perl_5_embedding Great work! Unfortunately, it still takes up to a minute for rakudo.org pages to load on my home machine. -- korajn salutojn, juerd waalboer: perl hacker [EMAIL PROTECTED] http://juerd.nl/sig convolution: ict solutions and consultancy [EMAIL PROTECTED]