Ohayou. I think what ur asking is why does @code change when u loop over it
with foreach, ne? This is because foreach only takes a reference to the
list values, it doesn't create a copy. So changing the iterand changes the
original value. If u don't want this u have to make ur own copy of the
v
?? ? <> wrote:
> 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($_) }
>
>
l 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
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?
#