Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Is this possible

by radiantmatrix (Parson)
on Mar 24, 2008 at 15:11 UTC ( #675913=note: print w/ replies, xml ) Need Help??


in reply to Is this possible

Well, you can get a lot of this done using File::Find and Text::CSV_XS. Some example code:

use strict; use warnings; use Text::CSV_XS; use IO::File; use File::Find; my (%data, @file); my $in_csv = Text::CSV_XS->new({ sep_char => " " }); #space-sep in my $out_csv = Text::CSV_XS->new({ sep_char => "\x09" }); #tab-sep out my $out = IO::File->new('report.tab','>') or die "Can't open report.tab for writing: $!\n"; find(\&parse_file, '.'); #find files, running parse_file() for each $out_csv->print($out, [ 'Name', @file ]); ## write out report foreach my $name (sort keys %data) { my @row = ($name); foreach (@file) { push @row, $data{$name}{$_}; } $out_csv->print($out, \@row); } sub parse_file { # only deal with *files* that match naming convention return unless -f $_ && m/RESULTS_FILE\.(\d+)/; my $file_number = $1; # captured number from match my $filename = $_; push @file, $filename; my $io = IO::File->new($filename,'<') or do { warn "Can't open $filename: $!\n"; return; }; while (my $row = $in_csv->getline($io)) { # e.g. first row in your example results in: # $data{Kostas}{RESULT_FILE.1} = Number1 $data{ $row->[0] }{ $filename } = $row->[1]; } }

I think you'll find that very fast and maintainable.

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet


Comment on Re: Is this possible
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://675913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2015-07-05 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls