I have some misunderstanding. The next code has the same behaviour. But I was thinking differently...
#!/usr/bin/perl use strict; print "TEST3 start...\n"; my @code; push @code, "01"; push @code, "02"; push @code, "03"; for (1..2) { test_val($_) } sub test_val { my $p = shift; print "test_val p=$p\n"; foreach my $val (@code) { print "val1=$val\n"; $val =~ s/^0+//; print "val2=$val\n"; } } __END__ C:>TEST3.pl TEST3 start... test_val p=1 val1=01 val2=1 val1=02 val2=2 val1=03 val2=3 test_val p=2 val1=1 val2=1 val1=2 val2=2 val1=3 val2=3 > -----Original Message----- > From: H.T. > Sent: Tuesday, September 09, 2008 2:30 PM > To: 'perl-win32-users@listserv.ActiveState.com' > Subject: Referenced data changing > > Hello, > > I'm just maintain this odd script. > On the code; > foreach my $val (@{$$code{"1"}}) { > I think $val is lexical but in the 2nd call of test_val > the data is changed. > I don't want it. > I must code like; > my $val2 = $val; > $val2 =~ s/^0+//; > to avoid the changing. > > I cann't understand why? > > #!/usr/bin/perl > use strict; > print "TEST1 start...\n"; > my %code; > push @{$code{"1"}}, "01"; > push @{$code{"1"}}, "02"; > push @{$code{"1"}}, "03"; > > for (1..2) { test_val($_, \%code) } > > sub test_val { > my $p = shift; > my $code = shift; > print "test_val p=$p\n"; > foreach my $val (@{$$code{"1"}}) { > print "val=$val\n"; > $val =~ s/^0+//; > print "val=$val\n"; > } > } > > __END__ > > > C:>TEST1.pl > TEST1 start... > test_val p=1 > val=01 > val=1 > val=02 > val=2 > val=03 > val=3 > test_val p=2 > val=1 > val=1 > val=2 > val=2 > val=3 > val=3 > > Regards, > H.T. > _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs