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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.