in reply to Re: Use Perl's Sort to only sort certain lines in a file?
in thread Use Perl's Sort to only sort certain lines in a file?

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.