Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi , I'am trying to update a

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi ,

I'am trying to update a text file. But somehow it does not work. I gets the following error:

Can't "next" outside a block at PersonalfrmList.pl

Here a snippet of my code:

open(IN,"c:\\h\\CSSCS\\bin\scripts\\ListofFile.txt")|| die "Can't open ListofFile.txt for update:$!\n";
@lines =<IN>;
close IN;

my $change_count = 0;
@lines = map {$change_count++ if s/&quot;cat&quot;/&quot;dog&quot;/sgi; $_ } @lines;
next unless $change_count;

open(OUT,&quot;>c:\\h\\CSSCS\\bin\\scripts\\ListofFile.txt&quot;) || &quot;can't open file for writing: $!\n&quot;;
print OUT @lines;
close OUT;


Can anyone tells me what I did wrong?

-thanks kirk124
 
Can you explain more precisely what it is that you are trying to do?

Duncan
 
Kirk,

What's this bit supposed to do?
Code:
my $change_count = 0;
@lines = map {$change_count++ if s/&quot;cat&quot;/&quot;dog&quot;/sgi; $_ } @lines;
next unless $change_count;

==Paul
 
i think you would find the nice perl func.

foreach $line (@lines) {
#do stuff with $line
last if #your dog replace
}

the easiest way to iterate your array.

print your array back over the file handle
trunc file, close.
done.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top