It is important to show us the "crap" because that shows that you have at least made an effort. It is also important to show some of the data because a description may not be very clear. As you will have noticed from the earlier replies to your original message, we are inclined to grab an idea and run with it - even if it is hopelessly wrong.

After all that lecturing, here is a solution for you (I suggest you examine this carefully, then reply explaining how you think it works):

use warnings; use strict; while (<DATA>) { my $match = /(NP\s+)(U\s+)(Pu\s*)/i; last if ! ($_ = <DATA>); next if ! $match; chomp; my $NP = substr $_, $-[1], $+[1] - $-[1] + 1; my $N = substr $_, $-[2], $+[2] - $-[2] + 1; (my $Pu = substr $_, $-[3]) =~ s/(\s)//g;; $NP =~ s/(\s)//g; $N =~ s/(\s)//g; print "NP $NP, N $N, Pu $Pu\n"; } __DATA__ 000 NP U Pu 001 1.270000 000001 3.141000 002 Lev N Pu 003 0.13 000001 3.277118 004 NP U Pu 005 1.000220 000002 3.098761 006 Yac S Yb 007 10.33000 000001 90000000

Note that the sample data is given as part of the script so tht other monks can simply download the entire thing and run it to see that it works. The sample given prints:

NP 1.2700000, N 0000013, Pu 3.141000 NP 1.0002200, N 0000023, Pu 3.098761

Perl is Huffman encoded by design.

In reply to Re^3: regex help! by GrandFather
in thread regex help! by igotlongestname

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.