ckj has asked for the wisdom of the Perl Monks concerning the following question:
my Text file:#!/usr/lib/perl use DBI; use strict; use Text::Table; my ($dir,@files,$file,$output_file,$line,%hash); $dir="D:/ckj/dummy"; chomp($dir); $output_file="D:/ckj/dummy/rep.txt"; opendir(DIR,"$dir") or die $!; @files=readdir(DIR) or die $!; close DIR; my $tb = Text::Table->new("NAME\n-------------------------", "Age\n--- +----------------------", "Department\n-------------------------"); open(FH1,">$output_file") or die $!; foreach $file (@files){ open(FH, "<$dir/$file") or die $! if($file=~/\.txt$/); while($line=<FH>){ %hash=(); while($line=~/employee name is/g){ my @name = split(" ",$'); $hash{"Name"}=$name[1]; } while($line=~/Age/g){ my @age = split(" ",$'); $hash{"Age"}=$age[1]; } while($line=~/Department/g){ my @dept = split(" ",$'); $hash{"Dept"}=$dept[1]; } $tb->load([$hash{"Name"},$hash{"Age"},$hash{"Dept"}]); } close FH; } print FH1 $tb; close FH1; print "Congratulations, report file has been saved as $output_file";
The employee name is : Ram Age: 25 years Department: HR The employee name is : Ravi Age: 28 years Department: HR The employee name is : Raju Age: 27 years Department: IT The employee name is : Ajay Age: 26 years Department: IT The employee name is : Rani Age: 25 years Department: IT
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need help in Text::Table
by Anonymous Monk on Jun 14, 2012 at 07:51 UTC | |
by Anonymous Monk on Jun 14, 2012 at 10:47 UTC | |
by ckj (Chaplain) on Jun 14, 2012 at 09:18 UTC | |
by Anonymous Monk on Jun 14, 2012 at 09:41 UTC | |
by Anonymous Monk on Jun 14, 2012 at 10:28 UTC | |
by Anonymous Monk on Jun 14, 2012 at 11:53 UTC | |
|
Re: Need help in Text::Table
by Khen1950fx (Canon) on Jun 14, 2012 at 13:17 UTC | |
by Anonymous Monk on Jun 14, 2012 at 13:33 UTC | |
|
Re: Need help in Text::Table
by Anonymous Monk on Jun 15, 2012 at 12:42 UTC |