igoryonya has asked for the wisdom of the Perl Monks concerning the following question:
my %file_system = ( '/path/subpath1/'=>['file1', 'file2', 'file3'], '/path/=>['fil01', 'fil02', 'fil03', 'fil04', 'fil05'], '/'=>['f001', 'f002'] ); my $cpath = ''; my @folders = sort keys %file_system; for my $folder (@folders){ print "$file_system{$folder}\n"; #Everythng is ok. Prints an array re +fernce, such as: ARRAY(0x3381e118) print join(';', @{$file_system{$folder}}), "\n"; #Everythng is ok. Pr +ints an array } my $listFolders = $win->BrowseEntry( -label=>'Folder:', -choices=>[@folders], #Also tried \@folders, and also, omitting -choi +ces parameter, used $listFolders->insert('end', @folders) -variable=>\$cpath, -browsecmd=>\&listFiles(); )->pack( -side=>'top', -anchor=>'nw', -fill=>'x', -expand=>1 ); #Testing $cpath, after selection: print "$file_system{$cpath}\n"; #Sometimes prints an array refernce, s +uch as: ARRAY(0x3381e118), sometimes not, even, though, visually, the + $cpath looks the same as the according path in the %fule_system var print join(';', @{$file_system{$folder}}), "\n"; #Sometime prints an a +rray, sometimes an array is NULL. #If I iterate keys %file_system, I see the path, that's in $cpath var, + but for some reason, it doesn't match. #Testing $cpath inside the function called from the Tk widget: sub listFiles{ print "$file_system{$cpath}\n"; #Sometimes prints an array refernce, +such as: ARRAY(0x3381e118), sometimes not, even, though, visually, th +e $cpath looks the same as the according path in the %fule_system var print join(';', @{$file_system{$folder}}), "\n"; #Sometime prints an +array, sometimes an array is NULL. }
Seems, like, sometimes, for some reason, -variable in the BrowseEntry returns the corrupt value, that doesn't match as a key in the original var, although, visually, looks the same, as in the original hash.
Update:Devel::Peek helped me to reveal that, indeed, it was an encoding problem, as Corion noted. I implicitly set an encoding and the problem went away
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: maybe, a corrupt selected entry in Tk::BrowseEntry
by Corion (Patriarch) on Dec 22, 2014 at 14:47 UTC | |
by igoryonya (Pilgrim) on Dec 22, 2014 at 15:31 UTC | |
by Corion (Patriarch) on Dec 22, 2014 at 16:22 UTC | |
|
Re: maybe, a corrupt selected entry in Tk::BrowseEntry
by Anonymous Monk on Dec 22, 2014 at 14:50 UTC | |
by igoryonya (Pilgrim) on Dec 22, 2014 at 15:39 UTC | |
by Anonymous Monk on Dec 22, 2014 at 15:43 UTC | |
by Anonymous Monk on Dec 22, 2014 at 15:45 UTC |