>>>>> "PJ" == Paul Johnson <p...@pjcj.net> writes:
PJ> On Fri, Sep 16, 2011 at 02:27:08PM -0400, Brandon McCaig wrote: >> my @column_headers = map trim($_), split /\|/, $header_line; >> Using an EXPR with map is even more confusing to me, but it seems to >> work here so I'll leave it at that. ;D PJ> map EXPR, @a is just the same as map { EXPR } @a. PJ> Some people will tell you that you should never use it. Some people PJ> will tell you that it is faster since perl doesn't have to create a PJ> scope. You can safely ignore all those people and use it when PJ> appropriate. i have never heard anyone say to never use the block form with map/grep. the expression form is usually fine but there are times when you need a proper block - i.e. when you have multiple statements. PJ> For me, it is appropriate when, as in this case, it reduces clutter and PJ> lets you focus on the intent of the code rather than the syntax. pretty simple syntax difference IMO. code blocks can only be the first arg and don't have a comma following them. you can even create your own subs with that syntax with prototypes (one of the few good uses for them). see File::Slurp::edit_file for an example. you can't create a sub which takes a bare expression like map/grep so you can only use the code block syntax there. uri -- Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com -- ------------ Perl Developer Recruiting and Placement Services ------------- ----- Perl Code Review, Architecture, Development, Training, Support ------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/