Here is a different strategy for tackling the problem that can have some serious performance advantages:
#! perl -slw use strict; my $rec = chr(0) x 123; my @type3l = split ':', '02:10:33:15:19:10:3:18:6:4'; my $n = 0; my @type3o = map{ $n += $_; $n - $_; } @type3l; my @type3 = map \substr( $rec, $type3o[ $_ ], $type3l[ $_ ] ), 0 .. $# +type3o; my @typeOl = split ':', '02:98:11:9'; $n = 0; my @typeOo = map{ $n += $_; $n - $_; } @typeOl; my @typeO = map \substr( $rec, $typeOo[ $_ ], $typeOl[ $_ ] ), 0 .. $# +typeOo; while( <DATA> ) { substr( $rec, 0 ) = $_; if( /^03/ ) { print join '/', map $$_, @type3; } else { print join '|', map $$_, @typeO; } } __DATA__ 03002068454210482 000000004204.572011-04-14 + 19:53:41INTERNET C 750467375 ^M 0214833 + G02042954 ^M 03002068703214833 000000002558.662011-04-15 + 08:17:19INTERNET C 761212737 ^M 0211561 + 05601207284 ^M 03002068802911561 000000001463.702011-04-15 + 08:40:52INTERNET C 719807216 ^M 029911 + 00100275296 ^M
Produces:
c:\test>junk92 03/0020684542/10482 /000000004204.57/2011-0 +4-14 19:53:41/INTERNET /C /750467375 / / 02|14833 + |G02042954 | 03/0020687032/14833 /000000002558.66/2011-0 +4-15 08:17:19/INTERNET /C /761212737 / / 02|11561 + |05601207284| 03/0020688029/11561 /000000001463.70/2011-0 +4-15 08:40:52/INTERNET /C /719807216 / / 02|9911 + |00100275296| [23:23:38.05] c:\test>
In reply to Re: Working with fixed length files
by BrowserUk
in thread Working with fixed length files
by vendion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |