First, a quick oneliner for fun:
perl -pe 'chomp if s/^START//..s/^END//; s/\S\K$/ /' input.txt
However, so far you haven't gotten an answer that sorts your fields the way you showed in your desired output, so I'll try my hand at that:
use warnings; use strict; my @ORDER = qw/ TIME ALT TEMP COLOR STRENGTH /; my %ORDER = map {$ORDER[$_]=>$_+1} 0..$#ORDER; local $/ = "\nEND\n"; while (<>) { s/\A.*^START\n(.*)^END\n/$1/ms; next unless /\S/; my @lines = grep {/\S/} split /\n/; @lines = map { $$_[0] } sort { return $$a[1] <=> $$b[1] if $$a[1] && $$b[1]; return -1 if $$a[1]; return 1 if $$b[1]; return $$a[2] cmp $$b[2] } map { /^(\w+):/ ? [$_,$ORDER{$1},$1] : [$_,0,$_] } @lines; print join(" ", @lines), "\n"; }
See Schwartzian transform and How do I sort an array by (anything)? for the sorting technique I used.
In reply to Re: Arrays & Output printing?
by haukex
in thread Arrays & Output printing?
by coding1227
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |