Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: How to improve speed of reading big files

by bv (Friar)
on Sep 18, 2009 at 13:46 UTC ( #796108=note: print w/replies, xml ) Need Help??

in reply to Re^2: How to improve speed of reading big files
in thread How to improve speed of reading big files

From the pos documentation:

pos directly accesses the location used by the regexp engine to store the offset, so assigning to pos will change that offset, and so will also influence the \G zero-width assertion in regular expressions.

So if we know that we have fixed-width data and we only want to match "foo", "ding", or "widget" starting at the 10th character of the string, we can assign to pos($string) to set the "last matched position" to something other than 0, and then use the \G anchor (technically a zero-width assertion, like ^ and $) like so:

while(<DATA>) { pos() = 10; print if /\G(?:foo|ding|widget)/o; } __DATA__ 3.14 PI foo 6.28 2PI ding 42 LUE answer 7 LUK superstition 87.32 UNK widget

This code prints lines 1, 2, and 5

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2023-12-06 17:12 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.