rovf has asked for the wisdom of the Perl Monks concerning the following question:
# @ctOutput : Content of some source file, containing # among others some 'include' directives foreach( @ctOutput ) { if( $_ =~ /^\s*include (.*)/ ) { open(INC, "<$1"); push @ctOutput, <INC>; # <==== !!!! close INC; } else { # process non-include lines here }
The funny part here is that @ctOutput is modified during the loop by *appending* the content of the included files at its end. Yes, I know, this looks also strange because the included lines are put at the end, and not at the place of the include statement, but in this particular application this is OK.
My question is about the modification of the LIST, which is usually not something we ought to do. But, aesthetics aside, is the construct
foreach (@x) { ..... push @x,'something'; ..... }
guaranteed to work, i.e. as long as we just extend the list at the end, will the program be portable? I personally doubt it will, but would like to know other opinions on it.
Ronald
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: It is weird, it is mad, but is it portable? (foreach question)
by Narveson (Chaplain) on May 20, 2008 at 09:47 UTC | |
by moritz (Cardinal) on May 20, 2008 at 10:51 UTC | |
|
Re: It is weird, it is mad, but is it portable? (foreach question)
by almut (Canon) on May 20, 2008 at 09:41 UTC | |
|
Re: It is weird, it is mad, but is it portable? (foreach question)
by carol (Beadle) on May 20, 2008 at 14:45 UTC | |
by ysth (Canon) on May 21, 2008 at 02:00 UTC |