In article <[EMAIL PROTECTED]>, Sudarshan Raghavan 
wrote:

> Kevin Pfeiffer wrote:
> 
>>In article <[EMAIL PROTECTED]>, Sudarshan Raghavan
>>wrote:
>>[...]
>>  
>>
>>>Reason: 'shallow copying' vs 'deep copying'
>>>Read through this link
>>>http://www.stonehenge.com/merlyn/UnixReview/col30.html
>>>    
>>>
>>
>>I looked at this article and tried the code but I get different/wrong
>>results (or am doing something wrong)...
>>
>>Using Data::Dumper...
>>
>>All three examples (the bad, the good, and the third way) yield:
>>
>>$VAR1 = {
>>          'games' => [],
>>          'bin' => $VAR1->{'games'},
>>          'nobody' => $VAR1->{'games'},
>>          'lp' => $VAR1->{'games'},
>>          'postfix' => $VAR1->{'games'},
>>          'named' => $VAR1->{'games'},
>>          'ftp' => $VAR1->{'games'},
>>          'at' => $VAR1->{'games'},
>>          'root' => $VAR1->{'games'},
>>          'mail' => $VAR1->{'games'},
>>          'pfeiffer' => $VAR1->{'games'},
>>          'daemon' => $VAR1->{'games'},
>>          'ntp' => $VAR1->{'games'},
>>          'uucp' => $VAR1->{'games'},
>>          'wwwrun' => $VAR1->{'games'},
>>          'man' => $VAR1->{'games'},
>>          'news' => $VAR1->{'games'},
>>          'sshd' => $VAR1->{'games'}
>>        };
>>
> 
> This should be the output of the bad one I guess. This will be the
> result of 'shallow copying' in this example
> 
>>
>>Here is the 3rd code example:
>>
>>  while (my @x = getpwent()) {
>>    $info{$x[0]} = [EMAIL PROTECTED];
>>  }
>>  for (sort keys %info) {
>>    print "$_ => $info{$_} => @{$info{$_}}\n"
>>  }
>>
>>As he writes, the array x gets reinitialized each time, then the reference
>>taken to it falls out of scope leaving behind an anonymous variable.
>>
>>But, something is broken I think... (bzw. I broke it)
>>  
>>
> 
> Are you sure about the output, I ran your code and it is working fine.
> We might be able to figure it out, if you can post all three of them
> together.

"User error" of course - I just threw all three examples into the same 
script, with same variable names, etc. Separately they work as expected.

Sorry for the confusion.

-K
-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to