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

[PBML] Re: Search and replacing text in a file

Expand Messages
  • Jeff Boes
    On Thu, 08 Oct 1998 14:02:29 -0700, webprogramming ... Something like this: use CGI :standard ; $word = param( word );
    Message 1 of 2 , Oct 8, 1998
      On Thu, 08 Oct 1998 14:02:29 -0700, webprogramming <info@...>

      >I need to search and replace a certain word in a text file from a webform
      >submission. The user would enter a word (in this case a domain name) in an
      >input box on a webform, and submit; the script would grab the text file ,
      >search for the word "template", and replace it with the domain name entered
      >by the user, save the file with a new name (domain_name.db) and close it. I
      >think I can do this with a while (<>) diamond operator , and a substitution
      >command. What would be the easiest way to do this.

      Something like this:

      use CGI ':standard';
      $word = param('word');
      open(FOO,'<file.ext') || die;
      open(BAR,'>newfile.ext') || die;
      while (<FOO>)
      print $_;

      This is just a skeleton, without much error checking or chrome, but it should
      get you started.

      Jeffery Boes
      jboes@... UIN 3394914 (ICQ: www.mirabilis.com)
      DBA/Developer/Web Engineer for hire
      "Sucking up bandwidth since 1994."
      For easy online travel reservations, go to Internet Travel Network:

      Subscribe, unsubscribe, opt for a daily digest, or start a new e-group
      at http://www.eGroups.com -- Free Web-based e-mail groups.
    Your message has been successfully submitted and would be delivered to recipients shortly.