Ashutosh Jog <[EMAIL PROTECTED]> wrote: > > This might be a very simple question, but being a newbie I > have to ask. :) > > How can I copy the line by line contents of a file to a array? > > For eg: @animals should look like > @animals = ('tiger','lion','elephant'); > > And the text file would have entries for the same in this order > (i.e. one after the other): > > tiger > lion > elephant
open ANIMALS, $filename or die "open: $filename: $!"; chomp( my @animals = <ANIMALS> ); But if, as often happens, you end up looping over the array once and then ignoring it, consider this instead: while (<ANIMALS>) { chomp; # something interesting } Which doesn't have to read the file into memory in order to loop over each line. -- Steve perldoc -qa.j | perl -lpe '($_)=m("(.*)")' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]