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


I want to avoid reading in the entire file, since I am under the impression that I can save memory that way, and it is very easy to let Perl take care of where in the string I am (tell), let me step through it (read) and jump to where I need to be (seek). All of this is possible, I'm sure, in a string, but I'm guessing not as easy.

Whether or not you are allowed to match via a pointer, I don't know. It isn't breaking anything, it just isn't working. I am not sure why it is not working, but I am under the impression that it is matching on the first record ID over and over again, and never moving on.

I could be wrong. I'll play some more and see.

-Travis

v2:

Okay, no, I can't match via the file handle. I can do <FIN>=~m//g;, but I imagine that is because it reads <FIN> into $_ and then does the m//g, which means I am reading in the entire file anyway! Nothing saved there, might as well read it all into $str.

-Travis

Replies are listed 'Best First'.
RE: $fileHandle =~ m//g;
by tye (Sage) on Aug 08, 2000 at 20:31 UTC

    Yes, you can use tell, seek, and read easily on a file handle. But you can't use a regular expression on a file handle so you need a major change to your approach.

    How big are the files? Perl uses lots of memory for most things, so reading even a moderately large file into memory probably isn't go to make much of a difference on memory usage.

    In any case, you're going to have to read in a big chunk of the file into a string (say $str) so that you can match a regular expression against that chunk. If you use ($str =~ m/.../g), then you can use $pos= pos($str) to see where you currently are in the string and pos($str)= $newpos to change where in the string to start matching against.

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