perlquestion
Grey Fox
Fellow Monks;</br>
I am having an issue trying to split a file whose fields are seperated by the '|' character. It seems to be treating the special character as undefined and splitting my file on each character.
<c>
#!/pw/prod/svr4/bin/perl
use warnings;
use strict;
use Data::Dumper;
#
# Purpose: Remove fields from emtoc file to facilitate title compare.
#
# I/O:
# Input: Complete Emtoc text file.
# Output: Emtoc file with index info missing.
#
# History:
# 01/23/09 - Created
#
my $FALSE = 0;
my $TRUE = 1;
my $debug = $FALSE;
if ( $#ARGV < 0 ) {
print "Usage: $0 [In File][Out File]\n";
exit(1);
}
my $emtocin = $ARGV[0];
my $emtocout = $ARGV[1] || 'cmpemtocout.txt';
# begin processing
open( FDIN, $emtocin ) || die "Could not open $emtocin\n";
open( FDOUT, $emtocout ) || die "Could not open $emtocout\n";
while ( my $record = <FDIN> ) {
print "Record is $record\n" if $debug;
#
# seperate fields according to the template
my @fld = split("|", $record );
#
# open output file and overwrite file
my $outrecord = join( '|',
$fld[0], $fld[3], $fld[4], $fld[5], $fld[6], $fld[7], $fld[8] );
print FDOUT "$outrecord\n";
}
close FDIN;
close FDOUT;
print "End of $0\n";
</c>
<p>Input Data</p>
<c>
file-101.pdf|BOOKMARK|4.2.5.4|71-00-03 Testing/Operating Limits|Goto_View_External|FIT_WIDTH|1|N/A
file-102.pdf|BOOKMARK|4.2.5.5|71-00-05 Storage/Transport|Goto_View_External|FIT_WIDTH|1|N/A
file-103.pdf|BOOKMARK|4.2.5.6|71-00-10 Component Replacement|Goto_View_External|FIT_WIDTH|1|N/A
file-104.pdf|BOOKMARK|4.2.5.6.1|LIST OF EFFECTIVE PAGES|Goto_View_External|FIT_WIDTH|1|N/A
file-105.pdf|BOOKMARK|4.2.5.6.2|HIGHLIGHTS|Goto_View_External|FIT_WIDTH|1|N/A
file-106.pdf|BOOKMARK|4.2.5.6.3|TABLE OF CONTENTS|Goto_View_External|FIT_WIDTH|1|N/A
</c>
<p>Output Results</p>
<c>
f|e|-|1|0|1|.
f|e|-|1|0|2|.
f|e|-|1|0|3|.
f|e|-|1|0|4|.
f|e|-|1|0|5|.
f|e|-|1|0|6|.
</c>
<p>Any help would be greatly appreciated</p>
<div class="pmsig"><div class="pmsig-565887">
-- Grey Fox</br>
"We are grey. We stand between the darkness and the light" B5
</div></div>