Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

RE: Length Field

by jlistf (Monk)
on Aug 08, 2000 at 20:54 UTC ( [id://26821]=note: print w/replies, xml ) Need Help??


in reply to Parsing and \G and /g and Stupid User Tricks: Length Field: post v0.2
in thread Parsing and \G and /g and Stupid User Tricks

that last parentheses, ($RID) should be an assertion, (?=$RID). if you don't do this, you will read in that ID and skip it the next time you read something. you don't need the \G unless there is pieces in the data that aren't going to match (it seems like everything in the data is a valid piece of data).

perhaps you want to use split instead of a regex? if every part of your data is getting tested, you probably don't need, or want, a regular expression. split the data on your $rid codes, and test the rest of the data. or since you're reading from a file... read till you hit a $rid code. test what you've read. continue till EOF.

Replies are listed 'Best First'.
s///
by THuG (Beadle) on Aug 08, 2000 at 21:04 UTC
    Yeah,
    If I'm having to read in the entire file anyway, then I might as well break it into seperate lines. I imagine s/($RID)/\n$1/g would do the trick (is that valid?). Then I don't have to hunt for the next record if the current one is FUBAR.

    -Travis
      you can do this without reading in the entire file all at once. start at a $RID code, read until you hit the next $RID code. what you just read will be one full record from the file. test it, etc. then continue. the only problem will be figuring out how to stop reading once you hit a rid code. you could do some combination of seek and read to read in some data, find a $RID code and seek backwards through the file to the beginning of the code. something like:
      $currpos = 0; while ( read( $dpf, $input, 80, $currpos ) ) { # get 80 characters from $currpos till EOF $input =~ m/($RID)(.*?)(?:$RID)/g; #grab a code, data and set pos # test $1 and $2 for errors $currpos = pos( $input ) # set pos in file to beginning of next id }
      i think that'll do it... i might be missing something though.

      jeff

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (None)
    As of 2024-04-25 04:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found