I have a list file consisting of a number of records e.g.
aaaa
bbbb
cccc
dddd
I do this to get them into an array
I now wish to do some work with each element in the list like thisopen APPLIST, $applistfile or die "Can't open $applistfile file: $!"; while (<APPLIST>) { push @inpfile, [split /\n/]; } close APPLIST or die "Cannot close $applistfile: $!";
The problem is that instead of $ifile being aaaa,bbbb etc..foreach my $ifile (@inpfile) { print STDOUT "\nFile $ifile being applied\n"; # First read the contents of the file into an array { local $/; open SLURP, $ifile or die "can't open $ifile: $!"; @filedata = <SLURP>; close SLURP or die "cannot close $ifile: $!"; } # split the data into each statement (i.e. between go's) my @filedata_new = (); foreach(@filedata) { push @filedata_new, split('go', $_); # split on the go } # now pass each statement to the opened connection and execute + it foreach my $statement (@filedata_new) { chomp($statement); $statement=~s/^\s+//; #print STDOUT "The statement being executed is $statem +ent\n"; my $sth = $dbh->prepare("$statement"); $sth->execute; } }
File ARRAY(0x11e6e8) being applied can't open ARRAY(0x11e6e8): No such file or directory
What am I doing wrong ?
In reply to foreach on array by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |