Re: Filehandle within foreach loop

2017-07-12 Thread Shawn H Corey
On Thu, 13 Jul 2017 00:50:42 +0530 perl kamal wrote: > open (my $FH, $file) or die "could not open file\n"; A quick note: output the file name and error message to have a better idea of what went wrong. open (my $FH, $file) or die "could not open file $file: $!\n"; -- Don't stop where th

Re: Filehandle within foreach loop

2017-07-12 Thread Jim Gibson
If you wish to terminate execution of a foreach loop without iterating over all of the elements (@files, in this case) use the “last” statement: foreach my $file ( @files ) { # process file open( my $fh, ‘<‘, $file ) or die(…); while( my $line = <$fh> ) { # process line } close ($fh) or d

Re: Filehandle within foreach loop

2017-07-12 Thread Chas. Owens
That code will read each line from each file. The problem is likely in the part that says: #[process the lines & hash construction.] What are you doing there? On Wed, Jul 12, 2017 at 3:23 PM perl kamal wrote: > Hello All, > > I would like to read multiple files and process them.But we could r

Filehandle within foreach loop

2017-07-12 Thread perl kamal
Hello All, I would like to read multiple files and process them.But we could read the first file alone and the rest are skipped from the while loop. Please correct me where am i missing the logic.Thanks. use strict; use warnings; my @files=qw(Alpha.txt Beta.txt Gama.txt); foreach my $file (@file