Q: File contents substitution

T

Troll

Hi,

I posted this in one of the other grps but have had no real luck yet. Sorry.

I need 2b able to change the contents of a file, ie. to substitute
occurences of 'one' to 'two'.
I have something like:
**************************
sub replace {
s/one/two/g;
}

open (INFILE, "+<test.txt") || etc...
while (<>) {
replace ();
}
**************************

Contents of test.txt are:
hello one
one ten one ten

What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...
Thanks in advance.
 
A

Anno Siegel

Troll said:
Hi,

I posted this in one of the other grps but have had no real luck yet. Sorry.

I need 2b able to change the contents of a file, ie. to substitute
occurences of 'one' to 'two'.
I have something like:
**************************
sub replace {
s/one/two/g;
}

open (INFILE, "+<test.txt") || etc...
while (<>) {
replace ();
}
**************************

Contents of test.txt are:
hello one
one ten one ten

What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...

Then read the FAQ instead, it's short and sweet. perldoc -q 'line in a file'.

Anno
 
T

Troll

Anno Siegel said:
Troll said:
Hi,

I posted this in one of the other grps but have had no real luck yet. Sorry.

I need 2b able to change the contents of a file, ie. to substitute
occurences of 'one' to 'two'.
I have something like:
**************************
sub replace {
s/one/two/g;
}

open (INFILE, "+<test.txt") || etc...
while (<>) {
replace ();
}
**************************

Contents of test.txt are:
hello one
one ten one ten

What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...

Then read the FAQ instead, it's short and sweet. perldoc -q 'line in a file'.

Anno

Anno,
Do I put
line in a file
in the search field on perldoc? Have never been there b4. What's the -q for?
 
A

Anno Siegel

Troll said:
Anno Siegel said:
Troll said:
Hi,

I posted this in one of the other grps but have had no real luck yet. Sorry.

I need 2b able to change the contents of a file, ie. to substitute
occurences of 'one' to 'two'.
I have something like:
**************************
sub replace {
s/one/two/g;
}

open (INFILE, "+<test.txt") || etc...
while (<>) {
replace ();
}
**************************

Contents of test.txt are:
hello one
one ten one ten

What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...

Then read the FAQ instead, it's short and sweet. perldoc -q 'line in a file'.

Anno

Anno,
Do I put
line in a file
in the search field on perldoc? Have never been there b4. What's the -q for?

-q lets perldoc search the faq for keywords. See "perldoc perldoc" for the
whole story.

Anno
 
T

Troll

*snip*
for?

-q lets perldoc search the faq for keywords. See "perldoc perldoc" for the
whole story.

Anno

OK, I got it. The script works now. Thanks very much :)
 
H

Helgi Briem

What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...

Then read the FAQ instead, it's short and sweet.
perldoc -q 'line in a file'.
Do I put line in a file in the search field on perldoc?
Have never been there b4. What's the -q for?

perldoc is a program that comes bundled with every
distribution of Perl.

You run it from a command line. If you used Unix
all of this would be obvious, so I'll assume you use
Windows. Go to the Start ->Programs->Accessories
menu and start "Command Prompt" to get a
command line window (Or Start -> Run -> cmd.exe)

-q is a command line switch and stands for "query"

Read
perldoc perldoc
for further info on how to use perldoc.
 
A

Anno Siegel

[perldoc]
-q is a command line switch and stands for "query"

I alsways thought it stood for faQ (because -f was taken by something
more important).

Anno
 
T

Troll

Helgi Briem said:
What am I missing to make this work? I'd love to read the manual [like
someone has suggested] but by the time I get there it'll be next year...

Then read the FAQ instead, it's short and sweet.
perldoc -q 'line in a file'.
Do I put line in a file in the search field on perldoc?
Have never been there b4. What's the -q for?

perldoc is a program that comes bundled with every
distribution of Perl.

You run it from a command line. If you used Unix
all of this would be obvious, so I'll assume you use
Windows. Go to the Start ->Programs->Accessories
menu and start "Command Prompt" to get a
command line window (Or Start -> Run -> cmd.exe)

-q is a command line switch and stands for "query"

Read
perldoc perldoc
for further info on how to use perldoc.

--
Helgi Briem hbriem AT simnet DOT is

Excuse the munged address. My last
e-mail address was killed by spammers.

You guessed right. Thanks Helgi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,801
Messages
2,569,658
Members
45,421
Latest member
DoreenCorn

Latest Threads

Top