On 1/4/06, chen li <[EMAIL PROTECTED]> wrote: > I think it might be natural for me to read the file > line by line and get the return position looks like > these(just an example), similar to do the word search > in microsoft Word, which is what I really want: > > match in line 1 and the end of matching position is 4 > > match in line 4 and the end of matching position is 24
perldoc -f pos http://perldoc.perl.org/functions/pos.html #!/usr/bin/perl while (<DATA>) { /(?<=bleh)/g && print "line $. matches [".pos($_)."]\n"; print substr($_, pos($_)-4, 4),"\n"; } __DATA__ slkdfjslkdfjdksfjdbleh sdfkjdblehblkdfjsldkfj sldfkjdklfdskfdblehasfkjdsklf slkdfjdkblehsldkfjdkfj -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>