Thanks for the help. This is what I have now. But there is a small problem.
#!/usr/bin/perl -w
print "\nWhat file would you like to open: ";
chomp($file = <STDIN>);
print "\nAttempting to open $file\n";
open(FILE, "< $file") || die "Unable to open file: $!\n";
open(OUT, "> '$file.new'") || die"Unable to create new file: $!\n";
while (<FILE>)
{
$count++;
$text = $_;
if ($text eq "go")
{
$gocount++ if s/^go/\//g;
print OUT;
}
}
print "\nThere are $count lines in the file\n";
print "Go count equal $gocount\n";
close(OUT) || die "Unable to close OUT file: $!\n";
close(FILE) || die "Unable to close file: $!\n";
It reads in 9 lines from the file. But only takes 1 go, changes it and writes that 1 to the new file. If I do a while $text eq "go" I get stuck in a loop. Have any clues. I need it to find every go in the file.
Here is the sample file.
go
go
go
go
sam
it
go
go
go
Thanks for the help,
Bobby
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.