Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - help writing to a file

 
Thread Tools Search this Thread
Old 07-10-2003, 07:25 AM   #1
Default help writing to a file


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
  Reply With Quote
Old 07-11-2003, 06:26 PM   #2
nobull@mail.com
 
Posts: n/a
Default Re: help writing to a file

"Kelly" <> wrote in message news:<0F7Pa.400187$. ca>...
> 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.
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump