Fellow Monks;
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.
#!/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";

Input Data

file-101.pdf|BOOKMARK|4.2.5.4|71-00-03 Testing/Operating Limits|Goto_V +iew_External|FIT_WIDTH|1|N/A file-102.pdf|BOOKMARK|4.2.5.5|71-00-05 Storage/Transport|Goto_View_Ext +ernal|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_Exte +rnal|FIT_WIDTH|1|N/A file-105.pdf|BOOKMARK|4.2.5.6.2|HIGHLIGHTS|Goto_View_External|FIT_WIDT +H|1|N/A file-106.pdf|BOOKMARK|4.2.5.6.3|TABLE OF CONTENTS|Goto_View_External|F +IT_WIDTH|1|N/A

Output Results

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|.

Any help would be greatly appreciated

-- Grey Fox
"We are grey. We stand between the darkness and the light" B5

In reply to Problem with split using a | seperator by Grey Fox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.