Thank you very much.That did work. A prime example of how painful being a newbie can be :)
Ahmer -----Original Message----- From: Amit Kulkarni [mailto:[EMAIL PROTECTED] Sent: Thursday, June 17, 2004 11:07 PM To: [EMAIL PROTECTED] Subject: Re: Subroutine return values mixed. HI , You need to declare @array "as my @array" after line 14 in subroutine. 13 sub color { 14 $map1 = shift; #NEW LINE- my @array ; 15 foreach $item(keys %$map1) 16 { push @array, $item;} 17 return [EMAIL PROTECTED]; 18 } Regards ------------------------------------------------------------------------ --- Amit Kulkarni. Software Engineer, Intellvisions Software ltd. off:-022-26875452 ext: 51 ------------------------------------------------------------------------ --- Everyone wishes to have truth on his side, but not everyone wishes to be on the side of truth. ------------------------------------------------------------------------ --- Khan, Ahmer H wrote: > Hi, I'm very new to Perl and am learning as I go along. I've been > reading a lot of articles and perl books to enhance my expertise. I'm > stuck on a problem where the content of the arrays returned back from > a common subroutine call are getting mixed up. > > Here is the code. > > ---------------------------------------------------------------------- > -- > ------------------ > 1 my %color_map = ( red => 'rouge', > 2 blue => 'bleu', ); > 3 > 4 > 5 my %grey_map = ( grey => 'white', > 6 greyblack => 'black', ); > 7 > 8 (*back1) = &color(\%color_map); ### Problem seems to be here. > 9 (*back2) = &color(\%grey_map); ### Data returned getting mixed due > to common sub calls. > 10 foreach (@back2) {print;} print"\n\n\n"; > 11 foreach (@back1) {print;} > 12 > 13 sub color { > 14 $map1 = shift; > 15 foreach $item(keys %$map1) > 16 { push @array, $item;} > 17 return [EMAIL PROTECTED]; > 18 } > ---------------------------------------------------------------------- > -- > ---------------------- > > The result looks like this. > > C:\TEMP\perl>perl testhash.pl > blueredgreygreyblack > > > blueredgreygreyblack > > I'm not sure why the content would get mixed up due to a common > subroutine call. On line 8 and 9, the common subroutine 'color' is > called once for each hash reference and subsequently the reference to > the array is returned back. Printing the arrays indicates mixed data > which obviously that I am doing something terribly wrong. Is there > another way to approach this? > > > Ahmer > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>