Morning all!

While I massively appreciate the scripts here I just feel like I'm not learning anything, which is not good for anybody :) I have in my head the logic (probably flawed at this stage) I want to use and I've started from scratch on something really simple so perhaps people could help me go down that path?

#!/usr/bin/perl use strict; use warnings; my $string = '0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ +'; my $len1 = substr $string, 0, 4; my $type = substr $string, $len1, 1; my $fragment = substr $string, $len1+1, $len1; my $nextpos = $len1+5; print " string: $string\n"; print " 1st data length: $len1\n"; print " data: $fragment\n"; print " type: $type\n"; print " next record lenth pos: $nextpos\n";
string: 0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ 1st data length: 0004 data: ADAM type: $ next record lenth pos: 9

The way I'd like to approach this is to start at beginning of the line and use the length string in each case to extract the string. So in the example above I use the '0004' to identify the data in the first field and then to identify where the next length marker for record 2 begins

What I'm stuck with is putting this into a loop so that it'll continue down the string, using each record length field as it goes, to strip out the data

Thanks!


In reply to Re^2: Splitting file into separate files based on record lengths and identifiers by monty77
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.