inspirio has asked for the wisdom of the Perl Monks concerning the following question:
Basically, I just need to print only the data with the <STANDARD> tag to $outfile and those with the >JN to $fixfile. Within the process I'm also trying to strip the <DIVIDER> tag which doesn't seem to work. Please help me out, here's the snippet:<DIVIDER>file.txt</DIVIDER> <STANDARD>.... .... ... <DIVIDER>file.txt</DIVIDER> >JN.... .... ....
Thanks!#!/bin/perl $infile=ARGV[0]; $outfile=ARGV[1]; $fixfile="fix.txt" open(INFILE,”$infile”) or die “can’t open $fixfile: $!” ; open(OUTFILE,”>$outfile”) or die “can’t open $outfile: $!”; open(FIXFILE,”>$fixfile”) or die “can’t open $fixfile: $!”; $/= “<DIVIDER>*</DIVIDER>”; $temp=""; while(<INFILE>) { $*=1; $temp=$_; if ( $temp=~ /^<STANDARD>(.|\n)+/ ){ $temp=~s/<(DIVIDER)>.+<\/\1>//; print OUTFILE $temp; } else { print FIXFILE $temp; } } close (INFILE); close (FIXFILE); close (OUTFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing on different output files.
by idle (Friar) on Feb 22, 2006 at 07:59 UTC | |
|
Re: Writing on different output files.
by spiritway (Vicar) on Feb 23, 2006 at 04:32 UTC | |
by Anonymous Monk on Feb 23, 2006 at 08:53 UTC |