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:
My next question

 



Cold-ice.com
Deleted

Jan 9, 2000, 12:21 AM

Post #1 of 2 (2203 views)
My next question Can't Post

I've got a file for example file.txt
and I need to read the 5th line of it and
set it into $line5 .

How do I do this ?

AND

How can I change the 5th line of file.txt
into for example "this is the 5th line !"

Thanks !


Borderline
Deleted

Jan 9, 2000, 4:05 AM

Post #2 of 2 (2203 views)
Re: My next question [In reply to] Can't Post

The answer to this is in Perlfaq5 Files and Formats
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


local($^I, @ARGV) = ('.bak', 'file.txt');
while (<> ) {
if ($. == 5) {
$line5 = $_;
print "his is the 5th line !\n";
next;
}
print;
close ARGV if eof; # Reset $.
}
</pre><HR></BLOCKQUOTE>
If you are doing this inside a block of code you want to do other stuf in undefine $^I line this
undef $^I

Hope this helped
Scott

 
 


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

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