Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting lines from a file.

Status
Not open for further replies.

perlone

Programmer
May 20, 2001
438
US
I have a file called news.txt and contains the following:

News 1
News 2
News 3

How do I delete on item from there for example how do i delete news 1? 'shift' is not working.
 
try this:

open (FH, "news.txt") or die $!;
@lines = <FH>;
close (FH);
# To delete the first element in the array @lines

pop @lines;

Something like that.

pearl2
 
yeah, pop should work in this situation. also, a more general purpose tool would be splice:[tt]
splice(@lines, 0, 1);
[/tt]
this would work to remove the 0th element of the array.

or

redefine the array with array slices:[tt]
@lines = @lines[1..scalar(@lines)];
[/tt]
this will also remove the 0th element of the array.

stillflame &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top