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

Re: [PBML] Search and Replace program help needed please

Expand Messages
  • Rodrigo Torres
    ... Seems not so dificult, let me see. You should use the eval bultin function. Will be something like this, but don t forget to read the documentation for
    Message 1 of 3 , Mar 18, 2005
    • 0 Attachment
      Em Sex, 2005-03-18 às 13:44 +0000, kumincam escreveu:

      > and my_prog.pl is the script

      Seems not so dificult, let me see.

      You should use the "eval" bultin function.

      Will be something like this, but don't forget to read the documentation
      for this funcion:
      perldoc -f eval


      #!/usr/bin/perl -w

      use strict;

      my $search_file = shift @_;
      my $text_file = shift @_;

      #or, in a more perlish way:
      #my ($search_file, $text_file) = @_;

      open SEARCH, $search_file or die "Couldn't open $search_file: $!";
      open TEXT, $text_file or die "Couldn't open $text_file: $!";;

      #We'll read __ALL__ lines of the search_file __AT_ONCE__
      #List context, beware.

      my @patterns = <SEARCH>;

      while(<TEXT>){
      #for each line of text, we'll walk over all the searchs

      foreach $operation (@patterns) {
      eval $operation;
      }

      print "$_\n";
      }

      close SEARCH;
      close TEXT;

      I think this works, try it. If you don't undertand any passage, fell
      free to ask.

      --
      motobói
    Your message has been successfully submitted and would be delivered to recipients shortly.