Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RFC: Simulating Ruby's "yield" and "blocks" in Perl

by LanX (Sage)
on Apr 22, 2013 at 16:52 UTC ( #1029925=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/ruby
    
    ...
       yield 2
    end
    test {|a| puts "You are in the block #{a}"}
    
  2. or download this
    /usr/bin/ruby -w /home/lanx/perl/ruby/yield.rb 
    You are in the method
    You are in the block 1
    You are again back to the method
    You are in the block 2
    
  3. or download this
    sub test {
      say "You are in the method";
    ...
    
    
    test b{ say "You are in the block $_[0]" };
    
  4. or download this
    use strict;
    use warnings;
    ...
    
    
    test b{ say "You are in the block $_[0]" };
    
  5. or download this
    /usr/bin/perl -w /home/lanx/perl/ruby/yield.pl 
    You are in the method
    You are in the block 1
    You are again back to the method
    You are in the block 2
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://1029925]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-09-29 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?