#!/usr/bin/perl -w use strict; use Data::Dumper; my @input=( '0010$ADAM SMITH0003*3330004%19770004$BOB 0001*40004%1967', '0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ' ); foreach my $data (@input) { print "\nSTARTING NEW LINE ......\ndata = $data\n"; while ($data) { print "\n"; my $len = substr($data,0,4); my $type = substr($data,4,1); my $stuff= substr($data,5,$len); substr($data,0,$len+5,''); #delete this "set of data" print "data length = $len\n"; print "data = $stuff\n"; print "type = $type\n"; } } __END__ STARTING NEW LINE ...... data = 0010$ADAM SMITH0003*3330004%19770004$BOB 0001*40004%1967 data length = 0010 data = ADAM SMITH type = $ data length = 0003 data = 333 type = * data length = 0004 data = 1977 type = % data length = 0004 data = BOB type = $ data length = 0001 data = 4 type = * data length = 0004 data = 1967 type = % STARTING NEW LINE ...... data = 0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ data length = 0004 data = ADAM type = $ data length = 0002 data = 33 type = * data length = 0005 data = TESTL type = L data length = 0005 data = TESTS type = S data length = 0005 data = TESTJ type = J data length = 0005 data = TESTZ type = Z

In reply to Re^3: Splitting file into separate files based on record lengths and identifiers by Marshall
in thread Splitting file into separate files based on record lengths and identifiers by monty77

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.