Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • See, this is exactly why I love Perl, cause there is always a something on CPAN that will make your life easier.

    use Sub::Current;

    print sub {
        my $num = shift;
        return $num < 2 ? 1 : $num * ROUTINE->($num - 1);

    - Stevan

    • That's great, but solve my 'yield' problem and I'll really love you :)

      • Well, all the "yield" and "block" stuff is just sugar around your basic continuation passing. So here is the translation of what the ruby is actually doing.


        use strict;
        use warnings;

            package Foo;
            sub new { bless { val => $_[1] } => $_[0] }
            sub inc { $_[0]->{val} += $_[1] }
            sub val { shift->{val} }

        sub testy {
            my ($args, $cont) = @_;
            my $foo = Foo->new(1);
            _testy($args, $foo, sub { $cont->($foo) });

        sub _testy {
            my ($args, $somefoo, $cont) = @_;
            foreach my $item (@$args) {

        testy([1,2,3], sub { print $_[0]->val, $/ });


        I tried wrapping some sugar around this, but it gets really messy with scoping. I suspect to do it right, you would need to do what Ruby does and make the subs into objects (Proc is what it is called in Ruby IIRC) and then wrap the sugar around that. Autobox might help here too, if for nothing more than removing the need to actually bless the subs.

        - Stevan