JimJx has asked for the wisdom of the Perl Monks concerning the following question:
abc1|0001|Yes
abc2|0002|Yes
abc3|0003|No
abc4|0004|No
....
abc100|0100|No
What I need to do is find the first occurance of No and change it to Yes. Pretty simple usually.... But for some reason, it will find the first occurance and change that and the next occurance also.
What I get is.
abc1|0001|Yes
abc2|0002|Yes
abc3|0003|Yes
abc4|0004|Yes
Any suggestions?
Thanks!
Jim
open INF,'</var/www/htdocs/cgi-bin/user.txt' or die "Can't open input +file"; my $flag = 0; while (<INF>) { local($^I, @ARGV) = ('.bak', 'user.txt'); while (<>) { if (/^(.+)(\|No)$/ && $flag != 1) { $flag = 1; print "$1|Yes\n"; ($Name,$Pass,$Used) = split /\|/,$_,3; } else { print; } } } close INF;
2006-10-17 Retitled by jeffa, as per Monastery guidelines
Original title: 'Driving me crazy.....'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem changing only first occurence of pattern in file
by japhy (Canon) on Oct 17, 2006 at 13:25 UTC | |
|
Re: Problem changing only first occurrance of pattern in file
by davorg (Chancellor) on Oct 17, 2006 at 13:26 UTC | |
by jwkrahn (Abbot) on Oct 17, 2006 at 17:48 UTC | |
|
Re: Problem changing only first occurence of pattern in file
by cephas (Pilgrim) on Oct 17, 2006 at 13:33 UTC | |
|
Re: Problem changing only first occurence of pattern in file
by nimdokk (Vicar) on Oct 17, 2006 at 13:27 UTC | |
|
Re: Problem changing only first occurence of pattern in file
by jdporter (Paladin) on Oct 17, 2006 at 15:12 UTC | |
|
Re: Problem changing only first occurence of pattern in file
by Hue-Bond (Priest) on Oct 17, 2006 at 13:27 UTC | |
|
Re: Problem changing only first occurence of pattern in file
by jwkrahn (Abbot) on Oct 17, 2006 at 14:40 UTC |