March 2014 Archives

map/grep is not a real iterator?

I always thought map/grep(and many functions in List::MoreUtils) is the way to functional program in perl5. but a small test tell me it's wrong:

test1: perl -e" do{print if $_ %1000 == 0} for(1..100_000_000);" #run successfully

test2: perl -e" map{print if $_ %1000 ==0} 1..100_000_000" #out of memory

seems map function create a array to accommodate all data from list. As I know, an iterator is just an cursor to traverse a lists which can be infinite or finite. but the present implementation of map sets feed list a limit to a ma…

About xiaoyafeng

user-pic I blog about Perl.