Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
I haven't found a problem yet that can't be solved by a well-placed trebuchet

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 scrutinizing the Monastery: (6)
As of 2016-06-26 17:51 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (331 votes). Check out past polls.