Could you explain me the "pos" trick ? | [reply] |
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)))
| [reply] [d/l] [select] |
| [reply] |