in reply to Report generation through formats

hello ankit.tayal560,

I abandoned the use of formats many years ago, and at first glance i think it is not possible to achieve what you want.

But as side note you have many uncautious statements:

L*

UPDATE: i'd go with something like:

use strict; use warnings; my $cur_pers = ''; my $sep = ('-'x70)."\n"; # print header print '=' x 70, "\n", (join "\t",('Name','Format of match', 'matches played','runs','scored','page 1')), "\n", '=' x 70, "\n"; while (<DATA>){ chomp; my @elements = split /!/,$_; # check if person change if ( $cur_pers ne $elements[0]){ print $sep; $cur_pers = $elements[0]; } print +(join "\t",@elements),"\n" } __DATA__ sachin tendulkar!ODI!434!12000 sachin tendulkar!Test!246!10900 sachin tendulkar!T20!189!5000 sourav ganguly!ODI!334!8000 sourav ganguly!Test!235!5000 sourav ganguly!T20!124!1800 rahul dravid!ODI!387!9000 rahul dravid!Test!212!5980 rahul dravid!T20!43!1345

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Report generation through formats
by ankit.tayal560 (Beadle) on Oct 14, 2016 at 07:19 UTC

    Thanks for the suggestions . I will definitely incorporate then into the script. but apart from using formats also is there any other way to achieve the results which I want??/

      For your report, printf is plenty sufficient (See sprintf for the formatting codes). For example:

      use strict; use warnings; my $APPROX_LINES_PER_PAGE = 4; my $sep = ('-'x60)."\n"; my $header = <<HEADER; ============================================================ Name Format of match matches played runs scored page %d ============================================================ HEADER my $format = "%-18s %-8s %-15s %s\n"; my $cur_pers = ''; my $page = 0; my $lines = 0; while (<DATA>){ chomp; my @elements = split /!/,$_; if (0 == $page or $lines >= $APPROX_LINES_PER_PAGE) { print $sep if $page; print "\n";# or do whatever you want to do between pages $page++; $lines = 0; $cur_pers = ''; printf $header, $page; } # check if person change if ($cur_pers and $cur_pers ne $elements[0]) { print $sep; $lines++; } $cur_pers = $elements[0]; printf $format, @elements; $lines++; } print $sep; print "\n"; __DATA__ sachin tendulkar!ODI!434!12000 sachin tendulkar!Test!246!10900 sachin tendulkar!T20!189!5000 sourav ganguly!ODI!334!8000 sourav ganguly!Test!235!5000 sourav ganguly!T20!124!1800 rahul dravid!ODI!387!9000 rahul dravid!Test!212!5980 rahul dravid!T20!43!1345

      I've added some sample pagination - I'm not sure what you had in mind there, but you should be able to extend it to what you wanted.

      Good Day,
          Dean

      Remove perl from the equation, write down the steps to achieve this, take the steps you have and apply them to your data. Go round this loop a few times to iron out the bugs. See Pseudocode. Once you have a working process then implement it in perl (or whatever).

        See Pseudocode.

        :) For the idea, but write the goals and steps in plain english or whatever you speak