saketh_hunk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am trying to write a perl script which shows the report like a table with below details: Branch Name: FileName changed| Author | revision number of the file 1)we use SVN as our version control tool, so our intention is to use svn commands and generate a basic report and then use perl script to neatly organize it. I am unable to allign the output as a table. Expected result: Branch Name: release_1 FileName Changed| Author | Revision Number of file changed| hello1.c | saketh1 | r120 hello2.c | saketh2 | r12 hello3.c | saketh3 | r100 Current/ERROR OUTPUT: Branch Name: release_1 FileName Changed| Author | Revision Number of file changed| hello1.c | saketh1 | r120 hello2.c | saketh2 | r12 hello1.c | saketh3 | r100

#!/usr/local/bin/perl require "List/MoreUtils.pm"; use strict; use List::MoreUtils qw(:all); my @FilePath=`svn log RepoUrl -v -q | awk '/paths/ { getline; print $1 + }'| awk -F' ' '{print \$2}'|awk -F'/' '{print \$NF}'`; my @Author=`svn log RepoUrl -q | awk -F'|' '{print \$2}'| awk 'NF' `; my @Revision=`svn log RepoUrl -q | awk -F'|' '{print \$1}'| sed 's/'-' +//g'| awk 'NF' `; my $branch=`svn info RepoUrl | grep ^URL | awk -F'/' '{print \$NF}'`; printf " Branch : $branch + \n" +; printf "|============================================================ +===================================================================== +=======|\n"; printf "| %-35s | %-35s | %-35s \n"," FILENAME ", " AUTHOR "," + VERSION "; printf "|============================================================ +===================================================================== +=======|\n"; my $result = each_array(@FilePath, @Author, @Revision); while ( my ($a, $b, $c) = $result->() ) { printf "$a"."\t"."$b"."\t"."$c"; } printf "|============================================================ +===================================================================== +=======|\n"; Expected result: Branch Name: release_1 FileName Changed| Author | Revision Number of file change +d| hello1.c | saketh1 | r120 hello2.c | saketh2 | r12 hello3.c | saketh3 | r100 Current/ERROR OUTPUT: Branch Name: release_1 FileName Changed| Author | Revision Number of file change +d| hello1.c | saketh1 | r120 hello2.c | saketh2 | r12 hello1.c | saketh3 | r100

Replies are listed 'Best First'.
Re: print a tabular report using perl
by toolic (Bishop) on Jan 12, 2016 at 18:12 UTC
Re: print a tabular report using perl
by Ratazong (Monsignor) on Jan 12, 2016 at 18:12 UTC

    Most probably your data contains linefeeds at the end (\n in $a, %b and $c). Try to remove them, e.g. using chomp.

    hth, Rata

Re: print a tabular report using perl
by Mr. Muskrat (Canon) on Jan 12, 2016 at 18:33 UTC

    Have you considered using a CPAN module to assist with this task?

    A search for SVN turns up quite a few modules including SVN::Log which looks promising for the task at hand.

Re: print a tabular report using perl
by kennethk (Abbot) on Jan 13, 2016 at 00:04 UTC
    A number of strong suggestions have been made here, but as a note, if you have a series of operations that involve accumulation of strings ending in newlines, you should probably use here-docs. In this case, your series of printfs:
    printf <<EOF, " FILENAME ", " AUTHOR "," VERSION "; Branch : $branch + |===================================================================== +===================================================================| | %-35s | %-35s | %-35s |===================================================================== +===================================================================| EOF
    Of course, given what you have there, print probably makes more sense than printf

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: print a tabular report using perl
by poj (Abbot) on Jan 12, 2016 at 18:25 UTC
    #!perl use strict; use List::MoreUtils 'each_array'; # test data my @FilePath = qw(hello1.c hello2.c hello2.c); my @Author = qw(saketh1 saketh2 saketh3); my @Revision = qw(r120 r12 r100); my $branch = 'Release1'; my $line = '|'.('='x113)."|\n"; my $fmt = "| %-35s | %-35s | %-35s |\n"; print ' 'x36,"Branch Name : $branch\n"; print $line; printf $fmt, ('FileName Changed','Author Revision','Number of file cha +nge'); print $line; my $result = each_array(@FilePath, @Author, @Revision); while ( my @f = $result->() ){ printf $fmt,@f; } print $line;
    poj
Re: print a tabular report using perl
by hotchiwawa (Scribe) on Jan 12, 2016 at 18:01 UTC
      It is too sophisticated , am looking for a simple one. Moreover, in order to implement them, first i need get the code to print multidimensional array elements

        This is about as simple as it gets. And it really is pretty simple. It handles a bunch of stuff for you that you will otherwise have to code for anyway.

        Look at Ratazong's advice if you're certain you want to push forward. It will get you pretty close to your expected output.

        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)