tag:blogger.com,1999:blog-5674879503126200888.post5077140026979947947..comments2023-10-22T06:30:57.331-07:00Comments on <a href="https://www.husseinnasser.com/p/about-hussein.html">Hussein Nasser</a>: Passing a function as a parameter to another functionHussein Nasserhttp://www.blogger.com/profile/18310476423554125845noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-5674879503126200888.post-447815608356558152009-07-06T12:20:01.995-07:002009-07-06T12:20:01.995-07:00Thanks @while1dan for the great references..Thanks @while1dan for the great references..Hussein Nasserhttps://www.blogger.com/profile/18310476423554125845noreply@blogger.comtag:blogger.com,1999:blog-5674879503126200888.post-66532852724785567702009-07-06T12:13:56.884-07:002009-07-06T12:13:56.884-07:00Perlmonks is a great website for Perl help. I hav...Perlmonks is a great website for Perl help. I haven't looked at their tutorials, but they're probably pretty good. http://perlmonks.org/?node=Tutorials<br /><br />I have learned a lot from perldoc http://perldoc.perl.org/Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5674879503126200888.post-47386086344399615302009-07-05T23:27:43.106-07:002009-07-05T23:27:43.106-07:00@I loved that language ! its simple man
This is pe...@I loved that language ! its simple man<br />This is perl?<br /><br />Thanks alot man for your great example.. <br /><br />do you have any good tutorialsHussein Nasserhttps://www.blogger.com/profile/18310476423554125845noreply@blogger.comtag:blogger.com,1999:blog-5674879503126200888.post-30451367117141463432009-07-05T19:59:14.936-07:002009-07-05T19:59:14.936-07:00map is a good example. It goes through an array, ...map is a good example. It goes through an array, passes each item to a function you provide and returns a new array containing the results.<br /><br />@original = (1, 34, 2, 25, 13, 3);<br />@doubles = map({ return $_ * 2 }, @original);<br /><br />Once this has run, @doubles will contain (2, 68, 4, 50, 26, 6).<br /><br />The first parameter to map is a function, the second is an array. Each item of the array is passed to the function as the parameter $_.<br /><br />By the way, the parentheses, comma, and return are unnecessary:<br /><br />@doubles = map { $_ * 2 } @original;<br /><br />Because of that, many programmers think it's just a weird language construct and don't realize they are passing a function to another function.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5674879503126200888.post-60300704840974152692009-07-01T14:10:20.607-07:002009-07-01T14:10:20.607-07:00@While1dan
Thanks for dropping by,
exactly, this ...@While1dan<br />Thanks for dropping by, <br />exactly, this is much more easier in Javascript as I know, i didn't use perl (i hope i will learn it soon) <br /><br />thanks for the great addition and valuable comment ...<br /><br />VB.NET isn't the language i suppose to use to describe this example i guess, I just used it for simplicty...<br /><br />Adding a perl example on how to do this i will be great ;) so readers can get the most benefit out of this post<br /><br /><br />Thanks friendHussein Nasserhttps://www.blogger.com/profile/18310476423554125845noreply@blogger.comtag:blogger.com,1999:blog-5674879503126200888.post-13506040753599234992009-07-01T11:41:34.987-07:002009-07-01T11:41:34.987-07:00This is a lot easier in more dynamic languages lik...This is a lot easier in more dynamic languages like JavaScript and Perl. It's even used commonly in their standard libraries.<br /><br />See JavaScript's setInterval, which takes either a function name or an actual function object.<br /><br />See Perl's map, grep and sort, which all take anonymous functions (though many users of these functions don't even realize they are passing functions).Anonymousnoreply@blogger.com