>>>>> "SCT" == Srinivasa Chaitanya T <tschaitanya....@gmail.com> writes:

  SCT>  How can I write functions which accept block as an argument?
  SCT> Basically I want to create a function with like which just
  SCT> executes the block and doesn't create an array.

this is one of the few places where perl's prototypes are useful. read
perldoc perlsub and look for the section on prototypes. it shows example
prototypes that parse like perl's builtin functions. there is one for
grep which has the same prototype as map.

you can also use a code reference instead and call that in your
sub. there isn't much difference between these:

        foo { /bar/ } 1, 2, 3 ;
        foo( sub { /bar/ }, 1, 2, 3 ) ;


the first is shorter but requires a prototype which the second
doesn't. and this pair of lines makes the call even shorter and is nice
if the bar() code is longer than a short expression.

        foo( \&bar, 1, 2, 3 ) ;
        sub bar { /bar/ } ;

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to