A newbie to Perl 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

open APPLIST, $applistfile or die "Can't open $applistfile file: $!"; while (<APPLIST>) { push @inpfile, [split /\n/]; } close APPLIST or die "Cannot close $applistfile: $!";
I now wish to do some work with each element in the list like this

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; } }
The problem is that instead of $ifile being aaaa,bbbb etc..
I get this instead

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.