CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Kanji; - Extension of the previous question you answered

 



zicero
Deleted

Sep 22, 2000, 9:21 AM

Post #1 of 3 (663 views)
Kanji; - Extension of the previous question you answered Can't Post

Kanji just taught me how to read/write to a specific line of an external file,
based on the lines number.

Now I am curious.
Is there a way to make PERL write to a line that equals something specific?

e.g. I have a file with the following lines:
- - - - - - - - - - www.zicero.dk www.cre8pc.com www.springrain.net www.perl.com www.sonique.com
- - - - - - - - - -

Can I make PERL write to a specific line,
based on what it says?
Have PERL to look for the line equaling www.springrain.net
and append, replace or modify something in it?
Instead of using the line number.

Thanks in advance.

Mick

------------------
http://www.zicero.dk


Kanji
User / Moderator

Sep 22, 2000, 9:32 PM

Post #2 of 3 (663 views)
Re: Kanji; - Extension of the previous question you answered [In reply to] Can't Post

Using my previous post as a frame of reference, check against the contents of $_ (the actual line) instead of $. (the line number).

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

while ( <> ) {
if ( /^www\.springrain\.net$/ ) { ... }


if ( $_ eq "www.springrain.net\n" ) { ... }
}</pre><HR></BLOCKQUOTE>

The eq method is more efficient but requires you removing the newline (\n) with chomp or -- as I did above -- append the newline to the wanted match.

If it makes it any clearer, you can use explicitly assign the variable the contents are read into instead of implicitly having them go to $_ by doing ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

while( my $line = <> ) {
if ( $line eq "...\n" ) { ... }
}</pre><HR></BLOCKQUOTE>

Hope that helps.


zicero
Deleted

Sep 23, 2000, 3:21 AM

Post #3 of 3 (663 views)
Re: Kanji; - Extension of the previous question you answered [In reply to] Can't Post

I apreciate the help. Thanks.

------------------
http://www.zicero.dk

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives