help writing to a file

Discussion in 'Perl' started by Kelly, Jul 10, 2003.

  1. Kelly

    Kelly Guest

    I want to search for a letter and replace it but when I add the > to the
    file name it acts up. When I take it out it works but obviously doesn't
    alter the file only prints it altered. Can anyone tell me why??

    use strict;
    my $content;

    ## Prompt user for file #############

    print "Enter the name of the file you would like to change...\n";
    chomp (my $file=<STDIN>);
    open (INFILE,">$file" || die "Cannot open $file");

    ## Prompt for old letter#############
    print "Enter the letter you would like to replace...\n";
    chomp(my $old=<>);

    ## Prompt for new letter ############
    print "Enter the letter you would like to replace $old with...\n";
    chomp(my $new=<>);

    ## Replace letters #
    while($file=<INFILE>){
    $content=$content . $file;
    }
    $content =~ s /$old/$new/sgi;
    close INFILE;

    print $content."\n";
    print "Press ENTER to quit";
    chomp ($file=<STDIN>);
     
    Kelly, Jul 10, 2003
    #1
    1. Advertising

  2. Kelly

    Guest

    "Kelly" <> wrote in message news:<0F7Pa.400187$>...
    > I want to search [...] and replace [...] file [...]


    This is FAQ: "How do I change one line in a file [...]?"

    This newsgroup does not exist (see FAQ). Please do not start threads here.
     
    , Jul 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    1
    Views:
    2,467
  2. BLF
    Replies:
    4
    Views:
    1,307
    Mike Treseler
    Aug 7, 2004
  3. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    817
    John Carnahan
    Jul 18, 2003
  4. HNguyen
    Replies:
    4
    Views:
    2,457
    HNguyen
    Dec 21, 2004
  5. drew
    Replies:
    6
    Views:
    191
Loading...

Share This Page