Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
How to split the file until the line matches another ..DN:#!/usr/bin/perl while(<DATA>){ chomp; if(/^\.\.(.*):$/) { $fh = output($output, $tag, $fh); $output = ""; $tag = $1; } $fh = output($output, $tag, $fh); } sub output { my ($output, $tag, $fh) = @_; if($output) { if($output =~ m/\.\.DN:(.*)/) { if($fh) { close($fh); } open($fh, '>', "$1.xml") or die "$1.xml: $!"; print $fh "$output"; } } return($fh); } # End of sub sroutine __DATA__ ..DN: 000044255 ..CB: ..SN: D046H6J5 ..PD: 20091030 ..DD: Friday, October 30, 2009 ..PY: 2009 ..ED: ..DN: 000044254 ..CB: ..SN: D046H6IR ..PD: 20091030 ..DD: Friday, October 30, 2009 ..PY: 2009 ..ED:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Split file
by BioLion (Curate) on Nov 09, 2009 at 17:42 UTC | |
by Anonymous Monk on Nov 09, 2009 at 17:52 UTC | |
|
Re: Split file
by bichonfrise74 (Vicar) on Nov 09, 2009 at 18:03 UTC | |
|
Re: Split file
by arun_kom (Monk) on Nov 09, 2009 at 20:39 UTC |