ankit.tayal560 has asked for the wisdom of the Perl Monks concerning the following question:
I want to read a file named sports.txt and generate a report in a file named blank.txt with proper formatting. I've written this code to perform the task but the format in which I want the report I am unable to get that
CODE : format DATA2= ------------------------------------------------------------ @<<<<<<<<<<< @<<<<<<<<< @######### @######## $name $format $matches $runs ------------------------------------------------------------ . format DATA2_TOP= ============================================================ Name Format of match matches played runs scored page@<< $% ============================================================ . #select(DATA2); open(DATA,"<C:/Perl/perl_tests/sports.txt"); @array=<DATA>; close(DATA); open(DATA2,">>c:/perl/perl_tests/blank.txt"); foreach(@array) { chop; ($name,$format,$matches,$runs)=(split(/!/)); write(DATA2); } open(DATA2,"<c:/perl/perl_tests/blank.txt"); while(<DATA2>) { print("$_\n"); } close(DATA2);
FORMATTED REPORT WHICH I AM GETTING IS : ============================================================ Name Format of match matches played runs scored page 1 ============================================================ ------------------------------------------------------------ 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 134 ------------------------------------------------------------
FORMATTED REPORT WHICH I WANT IS : ============================================================ Name Format of match matches played runs scored page 1 ============================================================ ------------------------------------------------------------ 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 134 ------------------------------------------------------------
sports.txt file is : 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
Any Suggestions about how to proceed with this issue?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Report generation through formats
by Discipulus (Canon) on Oct 14, 2016 at 07:08 UTC | |
by ankit.tayal560 (Beadle) on Oct 14, 2016 at 07:19 UTC | |
by duelafn (Parson) on Oct 14, 2016 at 10:18 UTC | |
by marto (Cardinal) on Oct 14, 2016 at 07:24 UTC | |
by Anonymous Monk on Oct 14, 2016 at 08:08 UTC | |
|
Re: Report generation through formats
by RonW (Parson) on Oct 14, 2016 at 16:10 UTC | |
|
Re: Report generation through formats ( Perl6::Form )
by Anonymous Monk on Oct 14, 2016 at 07:15 UTC |