seni has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; my $inFile = 'fanca.txt'; open (IN, $inFile) or die "open $inFile: $!"; my %user; while (my $line = <IN>) { next unless $line =~ m{^(\S+) (\d+) (.*)}; my ($site, $userID, $data, $data2) = ($1, $2, $3, $4); $user{$userID}{$site} = $data, $data2; } close(IN) or die "close $inFile: $!"; my $outfile = "parsingoutput_for_fanca.txt"; open(REPORT, ">$outfile") or die "open >$outfile: $!"; foreach my $userID (sort {$a <=> $b} keys %user) { my %sites = %{$user{$userID}}; my $line1 = 'SITES'; my $line2 = "$userID"; while (my ($site, $data, $data2) = each %sites) { $line1 .= ' ' x (length($line2)-length($line1)); $line2 .= ' ' x (length($line1)-length($line2)); #add on next site $line1 .= ' '. ' ' . $site; $line2 .= ' '. ' '. $data . ' ' . ' '. $data2; } print REPORT $line1 . "\n"; print REPORT $line2 . "\n"; print REPORT "\n"; } close (REPORT) or die "close $outfile: $!";
2006-10-28 Retitled by GrandFather, as per Monastery guidelines
Original title: 'Should be easy....'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modifying a regex
by grep (Monsignor) on Oct 27, 2006 at 17:48 UTC | |
|
Re: Modifying a regex
by bobf (Monsignor) on Oct 27, 2006 at 17:53 UTC | |
by seni (Initiate) on Oct 27, 2006 at 18:03 UTC | |
by seni (Initiate) on Oct 27, 2006 at 18:31 UTC | |
by grep (Monsignor) on Oct 27, 2006 at 19:34 UTC | |
by Anonymous Monk on Oct 27, 2006 at 20:15 UTC | |
by grep (Monsignor) on Oct 27, 2006 at 21:00 UTC | |
by seni (Initiate) on Oct 27, 2006 at 20:21 UTC |