http://qs321.pair.com?node_id=282966

kirk123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I am trying to update a text file. The error I am getting is:

Can't "next" outside a block at PersonalfrmList.pl line 59
Here a snippet of my code:
open(IN,"c:\\h\CSSCS\\bin\\scripts\\ListofFile.txt") || die "Can't ope +n ListofFile.txt:$!\n"; @lines = <IN>; close IN; my $change_count = 0; @lines = map{$change_count ++ if s/ORGANIZT-3FC930/CSSCS/sgi;$_ } @lin +es; next unless $change_count; open(OUT,">c:\\h\\CSSCS\\bin\\scripts\\ListofFile.txt")|| "Can't open +file for writing:$!\n"; print OUT @lines; close OUT;

Can someone tell me what is wrong with my script?
---kirk

20030811 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: Updating a text file
by swkronenfeld (Hermit) on Aug 11, 2003 at 18:18 UTC
    Kirk, I *think* what you're trying to do is not rewrite the file unless it changed. If that's the case, then instead of your "next" line, do
    if($change_count) { open(OUT,">c:\\h\\CSSCS\\bin\\scripts\\ListofFile.txt") || "Can't op +en file for writing:$!\n"; print OUT @lines; close OUT; }
Re: Updating a text file
by dragonchild (Archbishop) on Aug 11, 2003 at 18:13 UTC
    What block are you next'ing out of? Your code doesn't have any for, foreach, or while loops ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Updating a text file
by blue_cowdawg (Monsignor) on Aug 11, 2003 at 18:23 UTC

        I am trying to update a text file. The error I am getting is: Can't "next" outside a block at PersonalfrmList.pl line 59
    As well you should. You aren't using "next" within a control or loop block so the error is correct.


    Peter @ Berghold . Net

    Sieze the cow! Bite the day!

    Nobody expects the Perl inquisition!

    Test the code? We don't need to test no stinkin' code!
    All code posted here is as is where is unless otherwise stated.

    Brewer of Belgian style Ales