in reply to Re^2: How do i search and extract commented lines from a file using perl?
in thread How do i search and extract commented lines from a file using perl?

Ok. I'm not going to focus on your entire program, but I'll show you one easy-to-understand way to skip over lines between two search terms.

#!/usr/bin/perl use warnings; use strict; my $comment = 0; while (my $line = <DATA>){ if ($line =~ m#/\*#){ $comment = 1; next; } if ($line =~ m#\*/#){ $comment = 0; next; } next if $comment; print $line; } __DATA__ this that /* comment line 1 comment line 2 comment line 3 */ the other adsf

-stevieb

  • Comment on Re^3: How do i search and extract commented lines from a file using perl?
  • Download Code

Replies are listed 'Best First'.
Re^4: How do i search and extract commented lines from a file using perl?
by BillKSmith (Monsignor) on Jun 26, 2015 at 18:29 UTC
    I recommend the same logic, but let the -n switch handle the input and looping.
    Bill