monty77 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; #Open data file and put it into variable open FILE, "<data.txt"; my $string = do {local $/; <FILE> }; #Set offset if there is a header record and add it to initial position my $offset = 0; my $currentpos = 0 + $offset; #Set lastpos = length of data my $lastpos = length($string); #Read until end of data while ($currentpos < $lastpos) { #Grab record length within data my $recordlength = (substr $string, $currentpos, 4); #Grab record type which is 5th char my $recordtype = substr $string, $currentpos+4, 1; #Using record length grab the record and put it into variable my $fragment = substr $string, $currentpos, $recordlength; #Calculate starting position for next record .. not used at present my $nextstartpos = $currentpos + $recordlength + 1; #Use if clause to identify only $ record types and print the record da +ta if ($recordtype eq '$') { print " record type: $recordtype\n"; print " data: $fragment\n"; #Inrement starting position for the next loop $currentpos = $currentpos + $recordlength; } }
Any ideas?
I've commented to try and explain what it does, it's working through a file identifying records of different types within it and printing certain record types to screen however it just hangs after printing the 1st record for me
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can someone tell me why this hangs??
by dasgar (Priest) on Aug 28, 2010 at 22:11 UTC | |
|
Re: Can someone tell me why this hangs??
by AnomalousMonk (Archbishop) on Aug 28, 2010 at 23:09 UTC | |
|
Re: Can someone tell me why this hangs??
by Old_Gray_Bear (Bishop) on Aug 29, 2010 at 00:01 UTC | |
|
Re: Can someone tell me why this hangs??
by ww (Archbishop) on Aug 29, 2010 at 00:18 UTC | |
|
Re: Can someone tell me why this hangs??
by TomDLux (Vicar) on Aug 29, 2010 at 01:46 UTC | |
by monty77 (Initiate) on Aug 29, 2010 at 04:08 UTC | |
|
Re: Can someone tell me why this hangs??
by toolic (Bishop) on Aug 28, 2010 at 23:20 UTC | |
by Anonymous Monk on Aug 28, 2010 at 23:39 UTC |