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.
  • has an idiomatic translation of "yield" (As well as "self" and "super"). As for perldoc -f, ri should do everything you want.
    • Actually, I can't seem to use your 'yield' as a direct translation. I'm missing something fundamental. I put together this in Ruby (very similar to my actual problem):

      class Foo
          attr_reader :val
          def initialize(val)
              @val = val
          def inc(some_val)
              @val = @val + some_val

      def testy(args)
          foo =
          _testy(args, foo) {
              yield foo

      def _testy(args,somefoo)
          for item in args

      testy([1,2,3]) {|x| puts x.val}

      That, as expected, prints 2, 4 and 7. However, attempting to translate that to Perl is not only exceedingly clumsy, it also doesn't seem to work and I can't figure out why.

      #!/usr/bin/env perl

      use strict;
      use warnings;

      use rubyisms;

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

      sub _testy(&@);

      sub testy (&@) {
          my ( undef, $args ) = @_;
          my $foo  = Foo->new(1);
          _testy { yield $foo } ($args, $foo);   # line 19

      sub _testy (&@) {
          my ( undef, $args, $somefoo ) = @_;
          for (@$args) {

      testy { print shift->val, $/ } ([1,2,3]);
      no block given (LocalJumpError) at line 19