Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by LanX (Saint)
on Apr 22, 2013 at 16:52 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-29 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found