On Sun, 10 Oct 2004 14:30:32 -0600, Siegfried Heintze <[EMAIL PROTECTED]> wrote: > > The map and the sort statements are strange. Why don't they require a comma > between the first and second arguments?
They are not special, they are just using a special semantic built into perl. Consider the following: ---------------------------------------------------------------------------------------- sub iterate(&@) { my $code = shift; &$code for @_; } @data = ( "jack", "jill", "jenny" ); iterate { print "Hello $_\n" } @data ---------------------------------------------------------------------------------------- The "iterate" function takes a CODE reference and an ARRAY of stuff (same as MAP and GREP and SORT). It will then blindly iterate over the array of stuff and invoke the code for each element. The basic rule is, a BLOCK OF CODE does not require a comma after it, because it is self-enclosing (ie, it has braces). Consider then, that since 'map {xx} @data' is actually parsing {xx} as a code reference, the same way 'my $prog = { some code}' does, you can also do sub sortfilter($$){ stuff } sort \&sortfilter, @data or even sub special_sort(&@) { my $sort_func = shift; sort $sort_func, @_ } You should probably read more on anonymous subroutines and code blocks. (and even closures). Cheers. David > > Thanks, > Siegfried > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>