On Sep 6, Harry Putnam said:

>IMPORTANT: I don't want techniques involving call back (remembered)
>operators and parens, I know how to piece those together for simple
>things like the file below.

Is there a reason for that limitation?  Oh well.  Anyway, here's a good
approach:

  while (<INPUT>) {
    print substr($_, $-[0], $+[0] - $-[0]), "\n" if /pattern/;
  }

For information about what the @- and @+ arrays represent, read 'perlvar'.

This is more or less the same as

  while (<INPUT>) {
    print "$&\n" if /pattern/;
  }

except it's not as evil.  (To find out why $& is evil, read 'perlvar'.)

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to