jaldama has asked for the wisdom of the Perl Monks concerning the following question:
Having trouble opening a file to read and append things to. Do I need to open the file to read, close, and then reopen for appending? I thought I could use >>+ and save some time.. The matching works fine, and output is boo, so it's getting up to that point.
if ($hostUrl =~ m/(org|net|com|co|edu|gov)/ ) { open NAGHOST, "+>>$host_file" or die "can't open the $host_fil +e $!"; print "\nboo\n"; while (my $line = <NAGHOST>) { #check for duplicate file if ($line =~ m/($hostName|$hostUrl)/) { print "Looks like the data you entered is already on f +ile\n"; } #no duplicate, move forward else { print "\nbah\n"; } }
output:
boo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Openind file for read+append
by Eliya (Vicar) on Feb 08, 2012 at 18:37 UTC | |
by MidLifeXis (Monsignor) on Feb 08, 2012 at 18:40 UTC | |
by jaldama (Acolyte) on Feb 08, 2012 at 18:46 UTC | |
|
Re: Openind file for read+append
by roboticus (Chancellor) on Feb 08, 2012 at 18:43 UTC | |
|
Re: Openind file for read+append
by Riales (Hermit) on Feb 08, 2012 at 18:41 UTC | |
|
Re: Openind file for read+append
by locked_user sundialsvc4 (Abbot) on Feb 08, 2012 at 22:09 UTC | |
by jaldama (Acolyte) on Feb 09, 2012 at 18:45 UTC |