As shown in the comments I have 3 text files (floor1.txt etc) which just contain a single line of text. When the while loop is commented out (as above) both foreach loops work fine and print out 3 floors on building 1 and 2, but when I try to use the content of the floor text files the code fails when it gets to building 2. What obvious thing am I missing here? Regards, Andy.# floor1.txt # This files contains info about floor 1. # floor2.txt # This files contains info about floor 2. # floor3.txt # This files contains info about floor 3. use strict; use warnings; my @buildings = qw(building1 building2); my @floors = qw(floor1 floor2 floor3); my $current_building; my $floorfile; foreach (@buildings) { $current_building = $_; print "$current_building\n\n"; foreach (@floors) { $floorfile = $_ . ".txt"; print "$_\n"; # Why does the while loop, below, mess up the 2nd iteration of the for +each? # open FLOORFILE, $floorfile or die $!; # while (<FLOORFILE>) # { # print "$_\n"; # } } print "\n\n"; }
In reply to Problem with while loop inside a foreach loop by andylevel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |