How do I print to a specific part of a file?

They have: 62 posts

Joined: May 2000

I know how to print to the end of one, but how do I print, to, let's say, the 30th line of a file. Is that possible?

They have: 1,587 posts

Joined: Mar 1999

um, is there already data on the 30th line or is it blank?

------------------
CLICK 4 some tested resources for making money $, hosting, and web promotions.
My Site got hacked, but i'm coming back?

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 62 posts

Joined: May 2000

It would be blank.

They have: 850 posts

Joined: Jul 1999

Say you have a file containing
Where
were
you
night?

You want to add 'last' before night. if the file was currently in an @array, than night would be the third element. So, to make 'last' the third element, and night the fourth (and if there was another element after night, it would become the fifth etc), try using:

code:

$num  = 3; #remembere to take away 1 because it starts at 0 not 1
$file = 'text.txt';
$addition = "last\n"; #remember the newline \n

#Opening file and getting input
open(IN,$file) or die "Cannot open $file to read: $!";
@data = <IN>;	
close(IN);

#adding new element
splice(@data,$num,0,$addition);

#printing back into file
open(IN,>$file) or die "Cannot open $file to write: $!";
print IN @data;
close(IN);
[/code]

Hope that helps a little.

------------------
click here to help save lives
http://www.wiredstart.com  : The Technology Start Page 

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.