I think you're confusing yourself by using the term "split" in two different ways - one of which has nothing to do with splitting. You don't "split" a filehandle into an array, but you can slurp it - which is exactly what you're doing above, with the '@l=<FH3>' line. Perhaps what you mean is that you would like to process the array that you've created by slurping, one element (i.e., one line) at a time:

for my $line (@l){ chomp $line; # Remove the newline from the end print $line . " - processed by 'trenchwar'\n"; # Add a little co +ntent to each line }

Or you could do the same thing by using Perl's implicit iterator, '$_':

for (@l){ chomp; print "$_ - processed by 'trenchwar'\n"; }

or even by using the 'map' function:

chomp @l; # Remove the newline from all elements print map { "$_ - processed by 'trenchwar'\n" } @l;

I note, by the way, that your script has several doubtful constructs in it:

open (FH3, ">lessons.txt"); ### You should *always* check the return from any calls to the system. open FH3, ">lessons.txt" or die "lessons.txt: $!\n"; ### You should also close this filehandle; don't assume that your file + has actually ### been written before you do so! close FH3; $l="lessons.txt"; open(FH3, $l) || die("Could not open file!"); ### Don't create variables that you're only going to use once; just us +e the value. ### *And* check the return of the call. And don't pre-assume the reaso +n for failure: ### find out what it is with the '$!' (actual error) variable. open FH3, "lessons.txt" or die "lessons.txt: $!\n";

Update: Added a description of the errors in the script.


-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells

In reply to Re: Splitting an array loaded from a file handle. by oko1
in thread Splitting an array loaded from a file handle. by trenchwar

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.