If @arr is really supposed to be @ar, then it might be better to use $" (aka $LIST_SEPARATOR) to split and regenerate the string representing the array in the hash element that is to be sorted. It is the value of this special or predefined variable (see perlvar) that is used as a separator string when interpolating an array into a string in the first place.
Leaving out some of the intermediate, illustrative steps (qq{} is used instead of "" for double-quoting just to avoid the appearance of a bunch of \ escapes in the example code):
>perl -wMstrict -le "use English; use Data::Dumper; ; my @arr = ('Z', 'B', 'A'); my %x = ( period => '2010/05', typ => 'voice', tcon => 'A,B', hcon => qq{@arr}, ); ; print qq{hcon '$x{hcon}'}; ; my @array = split /\Q$LIST_SEPARATOR/, $x{hcon}; @array = sort @array; ; $x{hcon} = qq{@array}; ; print Dumper \%x; " hcon 'Z B A' $VAR1 = { 'tcon' => 'A,B', 'period' => '2010/05', 'hcon' => 'A B Z', 'typ' => 'voice' };
Update: Added metaquoting to split regex per tinita's suggestion. Also: using English version of $" to avoid any confusion introduced by Windoze command line escaping of " character.
In reply to Re^2: Sorting the hash
by AnomalousMonk
in thread Sorting the hash
by annem_jyothsna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |