Loading ...
Sorry, an error occurred while loading the content.
 

string and pattern matching. help please

Expand Messages
  • Chandra Reddy
    HI when your search patern might be in multiple lines u have you to use /g and for newline also to be matched /s . so try this s/$pattern/$replace/sg
    Message 1 of 1 , Sep 29 8:47 AM
      HI
      when your search patern might be in multiple lines
      u have you to use "/g" and for newline also to be
      matched "/s".
      so try this

      s/$pattern/$replace/sg

      chandra

      >I have a hard time matching and replacing this
      >pattern. It works fine
      >for single line but when I want to replace multiple
      >line pattern, it
      d>oesn't seem to work. I spend a lot of time on faq
      >but I guess I m
      >not
      >smart enough to figure out where I am going wrong. I
      >couldn't do it
      >using the regular exp. so I tried doing it using
      ?>Tie::File.

      >Please help me with this.

      ============================
      use Tie::File;
      use strict;
      use warnings;

      # tie @array to filename using Tie::File
      tie my @array, 'Tie::File', 'result.txt' or die
      "Cannot open
      result.txt:$!";

      while(<result.txt>){

      for(@array) {

      my $pattern = "The text

      to be

      searched

      in differnt

      lines inclunding white lines and indentation";
      my $replace = " The replacing
      text
      also in
      multiple lines
      including indentation and white lines ";

      s/$pattern/$replace/;

      }
      }
      untie @array;
      ==============================




      =====
      Chandra Redy Manubothu
      2555 Homestead Road,Apt#9
      Santa Clara,CA-95051
      740-707-4774(cell)

      __________________________________
      Do you Yahoo!?
      The New Yahoo! Shopping - with improved product search
      http://shopping.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.