develooper Front page | perl.perl5.porters | Postings from July 2001

turning EXPR into sub { EXPR }

Thread Next
Jeff 'japhy/Marillion' Pinyan
July 31, 2001 09:37
turning EXPR into sub { EXPR }
Message ID:
Could someone lend me a hand in turning an expression (or specifically,
the OP representing it) into an anonymous subroutine?

Here's what I've got so far, which lends itself to weird bugs:

  /* op.c:Perl_ck_subr */
  /* around line 6550 */

  OP* kid = o2;
  OP* sib = kid->op_sibling;
  kid->op_sibling = 0;

  /* japhy */
  o2 = newANONSUB(
    start_subparse(FALSE, CVf_ANON),
    block_end(block_start(TRUE), kid)

  o2->op_sibling = sib;
  prev->op_sibling = o2;

This is in an attempt to let

  sub foo (&@);


  foo /xyz/, @list;

as it would parse

  foo { /xyz/ } @list;

The thing I want to do is construct a OP_REFGEN op, which I see I can do
using newANONSUB.  The problem is that there seem to be some
subroutine-scope issues around this new code-ref.  For example:

  sub MY_MAP (&@) {
    my $cref = shift;
    for (@_) { print $cref->($_), "\n" }

  MY_MAP /i/, qw( this is bad );



For some reason, the argument itself is being returned in addition to the
return call.  I put in that block_end(block_start ...) stuff in an attempt
to alleviate the condition, but nope.

Any suggestions?

Jeff "japhy" Pinyan
RPI Acacia brother #734
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About