Nick,

Thanks for your help. Would you (or someone else) be able to help me further?

I'm using BBEdit as my text editor. When I copied your code and made a few edits (see below, NB. the html character code is that shift-opt-5 character) my outputted text became everything in the "if" section. The program then popped open a Unix Script Log window and contained within it is everything from the "else" section. However, nothing in this Log output is sorted.

while (my $line = <Input>) { $line =~ s{(z0)}{&#64257;$1}g; # $line =~ s{(?<=^)\n\Z}{&#64257;\n}g; if ($line =~ /^&#64257;/) { # line starts with a bracket if (@unsorted_input) { # if array has entries # my @sorted = sort two_way_sort @unsorted_input; print @unsorted_input; undef @unsorted_input; } print {Output} $line; # print the header line } else { # line is an entry line my @sorted = sort two_way_sort @unsorted_input; push @unsorted_input, $line; } } foreach my $line (@unsorted_input) { print Output $line; }

I'm not certain about what to do next.


In reply to Re^2: Use Perl's Sort to only sort certain lines in a file? by grahambuck
in thread Use Perl's Sort to only sort certain lines in a file? by grahambuck

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.