in reply to Re^2: text matching
in thread text matching

Hmmm. Can you show how you are running it? This is how my complete code looked:

#!/usr/bin/env perl use strict; use warnings; open my $in, "<", shift; while( my $line = <$in> ) { $line =~ s/ .* report s? .* ; .* //sx; print $line; }

Be sure to put the name of the report file as an argument on the CL. Also, which operating system are you using?

Replies are listed 'Best First'.
Re^4: text matching
by prassi (Acolyte) on Jun 16, 2012 at 06:54 UTC

    I am running the code in cygwin and here is my complete code.

    #!/bin/perl5.8.6 use warnings; use diagnostics; use File::Basename; @files = <../tryremove/*>; #This is the destination path where the comment removed files are crea +ted. $path1 = "C:/Projects/tryremove/c"; foreach my $file (@files) { my $filename =basename($file); open(file1,"$file") or die "The file cannot be opened the $file:$!\n +"; open(file2,">$path1/$filename") or die "The file cannot be opened:$! +\n"; while(!eof(file1)){ $/ = undef; $_ = <file1>; s# .* report [s]? .* ; .* ##sx; print file2 ($_); } close(file1); close(file2); }

      Thanks. Please delete the line:

      $/ = undef;

      and let me know if it works.

        it worked, can you help out what actually

        $/ = undef;

        would do. I am a newbie to perl try things to understand

      Here is the program using a different approach with the range operator.
      #!/usr/bin/perl use strict; use warnings; while (<DATA>) { if ((my $first = /^\s*#if/) .. (my $last = /^\s*#endif/)) { #print if $first || $last; print unless /^\s*reports?/; } else { print; } }

      Its a neat use of the range, ( .. ), operator.

      Chris

      Update: changed the first print line to more accurately perform what you needed.