Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach on array
by rduke15 (Beadle) on Oct 13, 2005 at 08:22 UTC | |
by tirwhan (Abbot) on Oct 13, 2005 at 09:18 UTC | |
by revdiablo (Prior) on Oct 13, 2005 at 14:38 UTC | |
by Anonymous Monk on Oct 13, 2005 at 08:36 UTC | |
|
Re: foreach on array
by shenme (Priest) on Oct 13, 2005 at 07:46 UTC | |
|
Re: foreach on array
by Rajeshk (Scribe) on Oct 13, 2005 at 08:50 UTC |