On Tue, May 12, 2009 at 14:30, AndrewMcHorney <andrewmchor...@cox.net> wrote: > Hello > > I put the strict and warning statements in my perl code. I now need to > initialize arrays. What is the best way to initialize an array before the > loop where I will basically recreating the array size in the loop? > > my @array = ? > > while (more work to do) > { > �...@array = split $string; > > # do work on array > } snip
The same way you created them before using strict: my @array = AN_EXPRESSION_THAT_YIELDS_A_LIST; Also, while loops are a bad way to process arrays, the for loop is much more natural: for my $element_of_array (@array) { } If this is the same code as before, you really shouldn't be using arrays like that. Files should be read using while (my $line = <$fh>) { } not my @array = <$fh>; my $i; while ($i < @array) { my $line = $array[$i++]; } -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/