Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: raw data formatting

by roboticus (Canon)
on Nov 16, 2012 at 00:24 UTC ( #1004086=note: print w/ replies, xml ) Need Help??


in reply to raw data formatting

teamassociated:

Part of the difficulty appears to be that the file may have some lines you want to discard. Since the $. variable keeps track of the lines read and not the lines wanted, using the modulo operator on it is going to fail. However, the modulo operator idea is a *good* one, you just need to keep track of the lines you want to keep yourself:

my $cnt_keepers=0; while (my $ln = <$f>) { next if .... # Now we've got a line we want to keep ++$cnt_keepers; if ($cnt_keepers % 5 == 0) { ... every fifth line processing ... } ... }

Another way you could do it is to simply accumulate the lines you want, and when you have five, process the lot of 'em:

my @records; while (my $ln = <$f>) { next if ... push @records, $ln; if (@records==5) { print "A $records[0]\n"; print "B $records[1]\n"; print "C $records[2]\n"; print "D $records[3]\n"; print "E $records[4]\n"; print "F $records[5]\n"; @records = (); } }

It may be coincidence, but it seems like the first record of each group always has a 'Z' (?record type indicator?) around column 20. If it's not a coincidence, then another way to handle it would be to accumulate records until you find a line with a 'Z' marker, then process all the records you have, and then put the new record into the accumulator.

Update: Fixed a code tag.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re: raw data formatting
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004086]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (18)
As of 2014-10-20 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (89 votes), past polls