in reply to create separate output files based on the matched values
The following does the trick. Note that the line ending for the created files is Windows rather than Mac or *nix style.
use warnings; use strict; my %files; while (<DATA>) { my ($name, $data) = /^(\w+)\s+(.*)/; last if ! defined $data || ! length $data; open $files{$name}, '>', "$name.out" if (! defined $files{$name}); syswrite $files{$name}, $data . "\r\n"; } close $files{$_} for (keys %files); __DATA__ T001 Test1 012354 Abcde T001 Test1 013456 bcdef T002 Test2 024567 xxxxx T001 Test1 012354 yyyyy T003 Test3 02345 cdefg T002 Test2 000000 56789
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: create separate output files based on the matched values
by Skeeve (Parson) on Sep 27, 2005 at 23:12 UTC | |
by GrandFather (Saint) on Sep 27, 2005 at 23:44 UTC | |
|
Re^2: create separate output files based on the matched values
by tariqahsan (Beadle) on Nov 10, 2005 at 19:02 UTC | |
by GrandFather (Saint) on Nov 10, 2005 at 19:22 UTC |