in reply to Parsing and \G and /g and Stupid User Tricks

Okay, here is what I've settled on doing. I will work on fine tuning it and cutting out unnecessary steps.

$RID = "MEH|MED|MMD|MMS|CR1|FR1"; open (FIN, "<file.dpf"); my $filecontents = <FIN>; $filecontents =~ s/($RID)/\n$1/ig; my @filecontents = split('\n', $filecontents); my $count = 0; foreach my $record (@filecontents) { print ++$count . "\t$record\n"; }


What the code is doing right now is spitting out each record, with a tally to the left, so I can see that it is working. Since each record will be on its own line, I don't have to hunt.

Now, just for better understanding, can I do the split without the substitution?

-Travis


v2: Leave it to Tye to find a problem. Okay, I can't do a global split. I think I have a way around it, let me try something.
  • Comment on RE: Parsing and \G and /g and Stupid User Tricks: Final Solution, v2
  • Download Code

Replies are listed 'Best First'.
RE: Final Solution: Parsing and \G and /g and Stupid User Tricks
by tye (Sage) on Aug 08, 2000 at 21:30 UTC
    local( $/ )= undef; @records= split /(?=($RID))/, <FIN>;

    Note that you need to set $/ if you want to read in the entire file at once.

    So a record can never have, for example, "MEH" in the middle of it? What kind of data is in these records that you can guarantee that these record IDs never appear in the middle of a record?

            - tye (but my friends call me "Tye")