Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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('','>') or die "Can't open 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.

Ramblings and references
The Code that can be seen is not the true Code

Comment on Re: Is this possible
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-27 14:42 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (177 votes), past polls