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")

In reply to RE: $fileHandle =~ m//g; by tye
in thread Parsing and \G and /g and Stupid User Tricks by THuG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.