in reply to Console Output Formatting Help Required
G'day tarunmudgal4u,
Without knowing exactly how the data is generated, it's a little difficult to give a clear answer on how to format it. While you do say there's message/status pairs, that doesn't address 'Mapped to V drive' (line 2) which doesn't have a status nor the source or importance of the blank lines you show.
In the code below, I've put the data you've posted into an Array of Arrays and processed that. You should be able to adapt the technique I've used for your needs.
#!/usr/bin/env perl use strict; use warnings; my @messages = ( ['Mapping a drive to build machine 10.211.32.254..', 'done'], ['Mapped to V drive'], [], ['Deleting TestHarness_LUA directory..', 'done'], [], ['Deleting TestHarness_LUA-distribution.zip file..', 'done'], [], ['Copying TestHarness_LUA-distribution.zip from mapped V drive..', + 'done'], ); for my $msg (@messages) { for (scalar @$msg) { $_ == 0 && do { print "\n"; last }; $_ == 1 && do { print_long_line($msg->[0]); print "\n"; last } +; $_ == 2 && do { print_long_line($msg->[0]); print "$msg->[1]\n +" }; } } sub print_long_line { print join "\n" => map { sprintf "%-55s" => $_ } shift =~ /(.{1,52 +})\b\s*/g; }
Output:
$ pm_format_long_line_output.pl Mapping a drive to build machine 10.211.32.254 done Mapped to V drive Deleting TestHarness_LUA directory done Deleting TestHarness_LUA-distribution.zip file done Copying TestHarness_LUA-distribution.zip from mapped V drive done
-- Ken
|
|---|