No $hashref2 = $VAR2->[$k]; is not deprecated, and what warning did you get?

Perl uses different operators for comparing numbers or strings.    See perlop for details.

Also, I was thinking about this code in your program:

push @array, $k; # Sort the array now because we pushed the value in ar +ray. my $srt; for (my $s=0;$s<@array; $s++) { for (my $r=0;$r<@array;$r++) { if ($s ne $r) { if($array[$s]<$array[$r]) { $srt=$array[$s]; $array[$s]=$array[$r]; $array[$r]=$srt; } } } }

You are adding one element to an array and then sorting the whole array using an algorithm that is O( N2 ).    And even if you switched to Perl's built-in sort function:

@array = sort { $a <=> $b } @array, $k;
that would at best be O( log N ).    However, you don't really need to sort the array, just insert $k in the correct place which would give you an O( N ) algorithm:

my $index = 0; ++$index while $k >= $array[ $index ]; splice @array, $index, 0, $k;

In reply to Re^3: Unexpected output for given program with write function by jwkrahn
in thread Unexpected output for given program with write function by dipesh777

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.