in reply to Re: foreach type of deal?
in thread foreach type of deal?
while (<>) { my $word = substr($_,1); # Start with the second letter }
As a note for the OP, while is a nicer option than Foreach Loops in this scenario since, in general, foreach constructs the entire list before incrementing over it, whereas while will just hit your file-handle once per loop -- normally, that means while has a much smaller memory footprint than foreach does for large sets. I don't recall if in the particular case of foreach(<$fh>) { there is an optimization in perl to avoid this pitfall.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: foreach type of deal?
by BillKSmith (Monsignor) on Mar 15, 2017 at 23:07 UTC |