Win has asked for the wisdom of the Perl Monks concerning the following question:
#! perl -slw use strict; my @files; my $file; while (<*.txt>) { next if $_ eq 'out.txt'; # next if $1 < 1990; $file = $_; push (@files, $_); } my $out = "out.txt"; open (OUT, "+>$out"); my $file_in_question; my $year; foreach (@files){ #print "Age\tMale\tFemale"; $file_in_question = $_; if ($file_in_question =~ /^(\d{4})/){ $year = $1; } open (FILE, "$file_in_question"); # print OUT "$year\t"; # This does not work print OUT for map{ ## And strip out the combined total. # print OUT "$year\t"; # This does not work s[(^\d+\s+)[\d\.]+\s+][$1]; $_; } sort { ## Sort the lines by age local $^W; ## Ignoring non-numeric warnings $a <=> $b } grep{ ## Remove any lines that don't fit the pattern m[^\d+\s] } map{ ## Split lines that fit the two column pattern into two m[(^\d+\s+(?:[\d\.]+\s+){3})(.+$)] } <FILE>; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: map function - print to file problem
by fishbot_v2 (Chaplain) on Oct 19, 2005 at 11:18 UTC | |
by Win (Novice) on Oct 19, 2005 at 12:25 UTC | |
|
Re: map function - print to file problem
by blazar (Canon) on Oct 19, 2005 at 12:29 UTC | |
by Win (Novice) on Oct 19, 2005 at 12:52 UTC | |
|
Re: map function - print to file problem
by Delusional (Beadle) on Oct 19, 2005 at 10:57 UTC | |
by Win (Novice) on Oct 19, 2005 at 11:05 UTC |