in reply to foreach my $var scope oddness

Hi

use strict; use warnings; my @outer = (qw| one two three |); print "First\n"; foreach my $o (@outer) { print $o, "\n"; } print "Second\n"; foreach my $o (@outer) { $o .= 'HIII'; print $o, "\n"; } print "ARRAY " , @outer , "\n"; #print $o, "\n"; # Comment out compile time error print "Third\n"; foreach my $o (@outer) { print $o, "\n"; }
Output :-
First one two three Second oneHIII twoHIII threeHIII ARRAY oneHIIItwoHIIIthreeHIII Third oneHIII twoHIII threeHIII
This is just to make you clear on what had happened in the following loop:-
foreach my $o (@outer) { $o .= 'HIII'; print $o, "\n"; }
The above loop actually modifies the value in the Memory region where it is pointing to. $o points the memory region of all indexes of array. so It modifies the element of array.

"Keep pouring your ideas"