Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Updating a text file

by kirk123 (Beadle)
on Aug 11, 2003 at 18:10 UTC ( #282966=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Updating a text file
Select or Download Code
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 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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://282966]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-12-27 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls