On Wednesday 05 May 2010, John W. Krahn wrote: > > If I could explain this further for Perl beginners: > > With that foreach statement, it reads the file first and creates an > > array with each line as elements and that array is being looped so the > > overhead is higher, whereas with that while statement, loop is > > processed whilst the file is being read and hence it's more > > appropriate. So while would be a better choice, more so if the file > > size is higher and there's a scope of closing the file before it's > > read completely. > > > > That's what I understood. Please correct me if there was anything > > incorrect with that. > > Yes, foreach reads the file into a list, not an array. > > perldoc -q "What is the difference between a list and an array"
Thanks for the explanation John. Could you give one or two real time examples where you used a list (instead of an array) except in loops such as: for ('a', 'b', 'c', 'd')? I wonder if I'm underusing lists in my Perl programs. -- Regards, Akhthar Parvez K http://Tips.SysAdminGUIDE.COM UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity - Dennie Richie -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/