Looking at the HTML source for your post. your data looks like this (I added code tags):
BRNO MAGNO SLOTNO PRODNO PRODREV 31 1 14 ROJ 208 882/1 R1C PRODNAM MANDATE SERNO MASTRP GED-DVD 20090604 CB49914646 1021 SLSTATE DATE TIME 0 120628 131219
To parse this, try the code below. Logic is complicated by the fact that the data format is not consistent, and it needs to handle several special cases.
#!perl use strict; use warnings; my (%val, @line); while (<>){ chomp $_; my $offset = /^(\s+)/?length($1) : 0; if (@line){ #print "$_ \[DATA]\n"; my @datavalues = split; if (scalar(@datavalues)==scalar(@line)){ for (0..$#datavalues){ $line[$_]{VALUE} = $datavalues[$_] ; #print "\[ $line[$_]->{NAME}=$line[$_]->{VALUE}] "; $val{ $line[$_]->{NAME} } = $line[$_]->{VALUE}; } }else{ for my $fld (@line){ $offset = $fld->{OFFSET}; $fld->{VALUE} = substr($_,$offset,length($fld->{NAME} +) + $fld->{TRAILINGSPACES} ); $fld->{VALUE}=~s/^\s+//; # Zap leading spaces $fld->{VALUE}=~s/\s+$//; # and trailing spaces #print "\[ $fld->{NAME}=$fld->{VALUE}] "; $val{ $fld->{NAME} } = $fld->{VALUE}; } } #print "\n"; @line=(); # Zap it }else{ while( m/(\S+)(\s*)/g){ push @line, {NAME=>$1, TRAILINGSPACES=>length($2),OFFSET=>$off +set}; $offset += length($1)+length($2); } #print "$_\n"; #print " Name =$_->{NAME} \t Tr.Spaces=$_->{TRAILINGSPACES} \t +off=$_->{OFFSET}\n" for @line; } } for (sort keys %val){ print " $_\t= $val{$_};\n"; }
Run like this
perl line-analysis.pl data1.txt
Output is:
BRNO = 31; DATE = 120628; MAGNO = 1; MANDATE = 20090604; MASTRP = 1021; PRODNAM = GED-DVD; PRODNO = ROJ 208 882/1; PRODREV = R1C; SERNO = CB49914646; SLOTNO = 14; SLSTATE = 0; TIME = 131219;

        "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams


In reply to Re: how to read values from a given paragraph by NetWallah
in thread how to read values from a given paragraph by get2vijay

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.