Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Input file: 88,100,2287432,1,0,400,2287432,52,12, ^M 16,275,2287432,0,0041880118XF,,/ ^M 88,REMARK : STANDING INSTR FROM: 323-126065 ADT FLOAT XFER CREDIT ^M 16,469,207805,0,2348128762TC,,/ ^M ________________________________________________________________ I'm trying to get rid of space before ^M.where ^M is a special charact +er (its one byte i.e ^M is one character)I'm using following code but + its not working.Any Suggestion please... Thanks. _______________________________________________________________ #!/usr/bin/perl open (diff, "<dave.00063"); + open (out, ">SAPPDAY.00063.new"); + $count=0; + while (<diff>) { + if (/(^16|^88)/) { + chomp $_ ; + @words=split(/,/, $_) ; + $field_cnt=$#words ; + #print " Field count = $field_cnt\n" ; + $last_length=length($words[$field_cnt]) ; + #print " Field length= $last_length\n" ; + $num1 =$last_length-1; + $num2 =$num- 1; + #print " NUM 1 = [$num1]\n" ; + if ( substr($words[$field_cnt], $num1, 1) eq " " ) { + $part1 = substr($words[$field_cnt], 0, $num2 ) ; + $part2 = substr($words[$field_cnt], $last_length, 1 ) ; + $words[$field_cnt] = $part1 . $part2 ; + print "$words[field_cnt]\n" + } + exit; + } + }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: substring function
by Fastolfe (Vicar) on Sep 29, 2000 at 20:04 UTC | |
by Anish (Novice) on Sep 29, 2000 at 22:36 UTC | |
by Fastolfe (Vicar) on Sep 30, 2000 at 01:16 UTC | |
|
Re: substring function
by ar0n (Priest) on Sep 29, 2000 at 19:17 UTC | |
by ar0n (Priest) on Sep 29, 2000 at 20:07 UTC | |
|
Re: substring function
by cianoz (Friar) on Sep 29, 2000 at 18:32 UTC |