yes the inherent problem is not to read in the start and end delimiter. I solved this by using if else conditionals which were refined down from using while/do statements that I had improperly constructed and ave me erroneous results. I have not yet practiced while/do statements especially with the !not operator. This looks like a very clean and 'flag-less' way to achieve the outcome of extracting the interior lines. In my exercise I was excited at the effective use of the boolean sense of the flag rather than in the original where I had employed the sense of comparison.(using 1/0 and not 1/2).
I am intrigued by the for ;!oef and !/$end_delim; conditional. I would not have come up with this as the for conditional you have provided only has two conditions where I am used to it having the incremental three. Though I recently put an array variable solely into a for() and it acted like a foreach. You have left out the initial value and used a non-incremental central conditional. However in this way it makes the for a lot more 'english' as you are saying 'for the remaining options, (after the do has exited) read in the line until either are returned true and exit before reading the delimiter in'.
so apart form the idea that the delimiters you are using are themselves boolean I can understand that you mean there is no need to add in unnecessary additional flags. Also in my case I would be fairly certain of not requiring eof delimiter conditions but it is good to see how do / while is used in practice. One of my aims is to expand the use of control structures from one of only using if/else conditionals.
in reference to LABELS: there may be the sense that overuse is in play but that is to help my understanding rather than for elegance. Though it appears that someone has something to say about labelling all too?
for the curious, and because I can't get to sleep thinking about do whiles - here follows the for with the sole array variable. It is a starting attempt to index array data from an initial array reference - as in what's in there? with a litle imagination to be developed to extract hash index too. I am aware this is most likely fully developed in Data::Dumper.
use strict;
use warnings;
my @AoA= ( #actual
[ "fred", "barney", "pebbles", "bambam", "dino", ], #ref
[ "george", "jane", "elroy", "jenks", ], #ref
[ "homer", "bart", "marge", "maggie", ], #ref
( "dave", "sam", "babby", "nan",), #actual
);
my $refAoA = \@AoA; #refofactual
for (@$refAoA){ #magic
if(ref $_){ print ref $_.$/;
for(@$_){
if($_ eq "elroy"){
print $_."if event".$/;
}else{print $_.$/;}
}
}else{
for($_){
print $_;
}
}
print $/;
}
do{$heep++} while !$leep;
exit(0);
My thinking is that the for would treat the array in a scalar context and produce an error but this looped through the arrays ref and actual and prints them out. |