Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Matching Question

by curtisb (Monk)
on Sep 20, 2002 at 20:17 UTC ( [id://199616]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://199616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-04-23 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found