in reply to Re: Matching Question
in thread Matching Question

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

Replies are listed 'Best First'.
Re: Re: Re: Matching Question
by mr2 (Friar) on Sep 21, 2002 at 09:38 UTC
    you need every line to be cmop'ed $_="go\n" ... chomp() does it.
    ... while (<FILE>) { $count++; $text = $_; ## this is what you need chomp($text); ## this is what you need if ($text eq "go") { $gocount++ if s/^go/\//g; print OUT; ...
      Thanks,
      That fixed the problem I was having. Now, I just have to figure out how to read something like this.
      CREATE TABLE "a2k"."DA2404_DISCREPANCY" ( "MR_CONTROL_NO" varchar(30) NOT NULL, "DISCREP_NO" integer NOT NULL, "TM_ITEM" varchar(4) NULL, "STATUS" varchar(1) NULL, "DEFICIENCY" varchar(30) NULL, "CORRECTION" varchar(30) NULL, "INITIALS" varchar(3) NULL, PRIMARY KEY ("MR_CONTROL_NO", "DISCREP_NO") WITH HASH SIZE 10 ) go
      I want to change VARCHAR to VARCHAR2. I know that the ^ is to anchor at the beginning of a line. What does the $ do, exactly?
      Thanks,
      Bobby